Re: about connect
- From: "Chinlu" <chinluchinawa@xxxxxxxxxxx>
- Date: 14 Jun 2006 10:29:38 -0700
It exits succesfully, I've been also trying playing arround the
server's code, but as I expected, if I call bind on 127.0.0.1 port 25 I
get a `permission denied' alike message,
As root?
Uh?, no I started it as root, but trying to connect as normal user, the
thing is probably that one cannot bind something which is already being
binded.
Damn! It's gone! Appended...
Thanks, I just have achieved it. Was completely missing linux/net.h
where sys_connect is defined.
It's a bit messy how this works, or at least is not what one would
expect, still haven't understood it properly, but I'm in the way.
Basically is as you said, socketcall is the system call, and then you
use one of the definitions in linux/socket depending on what you want
to do.
I just can't wait to try with a web-site address, and start sending and
receiving data, how amazing!
I should think that the "login" requirement would be "normal". I
wouldn't expect to have to use mime unless there are some "funny"
characters. But then, I haven't tried it.
Actually I haven't seen any that allows you plain authentication. All
where through mimencode, either in the form:
printf 'username\0username\0password' | mimencode
and issuing:
auth plain [above commands output here]
or alike, sometimes you need to append `@domain.level', sometimes not,
other is just with a single username and password. Or even other
accepting user and password by separate, where you just need to issue
an:
auth [mime-encoded username]
and replying with the enconde password, when the server asks for it (in
mime encoding as well).
In the case of google or servers that uses tls, one one to go by
open_ssl and auth plain.
Here's Scott's daytime client. "Works for me" - after enabling a daytime
server in /etc/inetd.conf...
Best,
Frank
/* daytime client in Linux asm, syscalls only
(as daytime -o daytime.o; ld -s daytime.o -o daytime)
*/
LITTLE_ENDIAN = 1 # set to 0 if host is big endian
_ip = 0x7F000001 #127.0.0.1, convert to hex yourself
_port = 13
# Convert numbers to network byte order
.if LITTLE_ENDIAN
IP = ((_ip & 0xFF000000) >> 24) | ((_ip & 0x00FF0000) >> 8) | ((_ip &
0x0000FF00) << 8) | ((_ip & 0x000000FF) << 24)
PORT = ((_port >> 8) & 0xFF) | ((_port & 0xFF) << 8)
.else
IP = _ip
PORT = _port
.endif
SYS_READ = 3
SYS_WRITE = 4
SYS_SOCKETCALL = 102
SYS_SOCKET = 1
SYS_CONNECT = 3
SYSCALL_VECTOR = 0x80
AF_INET = 2
SOCK_STREAM = 1
SA = -0x10
SIN_FAMILY = -0x10
SIN_PORT = -0x0E
SIN_ADDR = -0x0C
SIZEOF_SA = 16
STDIN = 0
STDOUT = 1
BUF = -0xA0
BUFLEN = 0x80
SOCK = -0x20
ARGS = -0x20
ARG0 = -0x20
ARG1 = -0x1C
ARG2 = -0x18
ARG3 = -0x14
.text
.globl _start
.align 4
_start:
pushl %ebp #setup stack frame
movl %esp, %ebp
# Fill out sockaddr_in struct
movw $AF_INET, SIN_FAMILY(%ebp)
movw $PORT, SIN_PORT(%ebp)
movl $IP, SIN_ADDR(%ebp) #inet_aton(127.0.0.1)
movl $0, -8(%ebp) #memset(sa.sin_zero, 0, 8)
movl $0, -4(%ebp) #
# socket(AF_INET, SOCK_STREAM, 0)
movl $SYS_SOCKETCALL, %eax #c.f. /usr/src/linux/net/socket.c
movl $SYS_SOCKET, %ebx #int call
movl $AF_INET, ARG0(%ebp)
movl $SOCK_STREAM, ARG1(%ebp)
movl $0, ARG2(%ebp)
leal ARGS(%ebp), %ecx #unsigned long *args
int $SYSCALL_VECTOR
cmpl $0, %eax
jl exit
# connect(sock, (struct sockaddr *)&sa, sizeof(struct sockaddr))
movl %eax, ARG0(%ebp) #sock
movl $SYS_SOCKETCALL, %eax
movl $SYS_CONNECT, %ebx #int call
leal SA(%ebp), %edx
movl %edx, ARG1(%ebp)
movl $SIZEOF_SA, ARG2(%ebp)
leal ARGS(%ebp), %ecx #ulong *args (see 'sock' above too)
int $SYSCALL_VECTOR
cmpl $0, %eax
jl exit
# read(sock, buf, len)
movl $SYS_READ, %eax #sys_read
movl SOCK(%ebp), %ebx #arg 1: fd
leal BUF(%ebp), %ecx #arg 2: buf
movl $BUFLEN, %edx #arg 3: count
int $SYSCALL_VECTOR
cmpl $0, %eax
jl exit
# write(stdout, buf, len)
movl %eax, %edx #len
movl $SYS_WRITE, %eax
movl $STDOUT, %ebx
leal BUF(%ebp), %ecx
int $SYSCALL_VECTOR
exit:
movl $1, %eax #sys_exit
int $SYSCALL_VECTOR
Thanks Frank, for your unvaluable help. I'm sending a link for what I
got already, one doesn't even need structures at the end of the day, as
I understand:
http://es.geocities.com/ucho_trabajo/asm/connect.s.txt
This is the output I get from strace:
socket(PF_INET, SOCK_STREAM, IPPROTO_TCP) = 3
connect(3, {sin_family=AF_INET, sin_port=htons(25),
sin_addr=inet_addr("127.0.0.1")}}, 16) = 0
_exit(0) = ?
Kind Regards,
.
- Follow-Ups:
- Re: about connect
- From: Chinlu
- Re: about connect
- References:
- about connect
- From: Chinlu
- Re: about connect
- From: Frank Kotler
- Re: about connect
- From: Chinlu
- Re: about connect
- From: Frank Kotler
- about connect
- Prev by Date: Re: win32 or native NT windows API
- Next by Date: Re: win32 or native NT windows API
- Previous by thread: Re: about connect
- Next by thread: Re: about connect
- Index(es):
Relevant Pages
|