ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I am trying to learn how to send data through the network, and I am having some concept issues. I post this thread asking about where packets are formed, but that is only half the story. http://www.linuxquestions.org/questi...hreadid=124500
From this post, I am under the thought that it would be best to make a system call to the O/S to handle the lower layers of the OSI. I would like to learn to do this without the a call to the O/S, but first things first. I know with video you can do an INT to the O/S, or do an INT to BIOS. I was wondering if there is the same type of thing with networking.
I am posting this question here because I can not find too much information on this subject when I do a search. I think mainly because I really don't have the concept down well enough to understand what exactly I am looking for. So if someone can either give me a brief summary on how to do it so I can explore more details on-line, or if you have any links that would be great. I know this subject I am asking about could probally take up a few chapters in a book.
To summerize my two questions.
1. How would you do a system call to send data through the network,
2. How would you set up the info. to be sent through the network. At some point the packet has to be completed. So if the system call to the O/S would handle from layer 3 down, how do I get the information into the form so it is ready for the third layer?
Again, I know this subject could cover chapters, but if you could give a brief summary, that would be very helpful.
my friend have you heard of the sockets interface? if you want to just send data over a network, there is the socket() family of system calls. googling for "beej's sockets tutorial" will find you a great guide to learning sockets on *nix. if you want to create RAW packets, where you form your own tcp/ip/icmp headers, you need to use a Raw Socket. you seem kind of confused.. writing socket code in assembly is not that hard, it can be annoying but once you learn a few tricks it isnt bad. however, writing assembly code to create packets will definitly be a bit harder. heh you reminded me of this bit of code i wrote a while ago.. a really crappy ping program that builds and ICMP header and just sends out a few echo requests...
Code:
.include "asm_defines.h"
;// constants
ADDR = 0xB34D4D4D ;// 77.77.77.178 in network byte order
NAP = 360000000 ;// 1 hour in seconds = time to sleep
;// variables are all stored on the stack at the following offsets
SA = -0x10 ;// struct sockaddr_in
SAFAM = -0x10
SAP = -0xE
SAIP = -0xC
SOCK = -0x14 ;//socket handle
BUF = -0x20 ;//send buffer
BUFSZ = 0xC ;//12 bytes
ARGS = -0x38 ;//function arg strings
ARG0 = -0x38
ARG1 = -0x34
ARG2 = -0x30
ARG3 = -0x2c
ARG4 = -0x28
ARG5 = -0x24
.text
.globl _start
_start:
pushl %ebp ;//save the old frame pointer
movl %esp, %ebp ;//use ebp to reference variables
;// first we clear out our memory
leal SA(%ebp), %ebx ;/load ebx with the address of starting memory to clear
movl $28, %ecx ;//load ecx with number bytes to clear (buffer + sockaddr_in) = (12 + 16)
zmem:
movb $0, (%ebx) ;//zero the byte in %bl
inc %edx ;//counter
inc %ebx ;//expose next byte
cmp %edx, %ecx ;//loop control
jne zmem
;//set up address struct
movw $AF_INET, SAFAM(%ebp)
movl $ADDR, SAIP(%ebp)
;//create the socket
;//socket(AF_INET, SOCK_RAW, IPPROTO_ICMP);
socket:
movl $SYS_socketcall, %eax
movl $SYS_socket, %ebx
movl $AF_INET, ARG0(%ebp)
movl $SOCK_RAW, ARG1(%ebp)
movl $IPPROTO_ICMP, ARG2(%ebp)
leal ARGS(%ebp), %ecx
int $0x80
movl %eax, SOCK(%ebp)
cmpl $0x1, %eax
jle exit
icmp:
;//setup the icmp header
leal BUF(%ebp), %eax
movb $0x08, (%eax) ;//type
movb $0x00, 0x1(%eax) ;//code
movw $0xfff5, 0x2(%eax) ;//checksum 2 bytes
movw $0x0001, 0x4(%eax) ;//ID 2 bytes
movw $0x0001, 0x6(%eax) ;//SEQ 2 bytes
xorl %esi, %esi ;//esi is the counter for sending packets
send: ;//we cant use 2 memory operands in one expression, hence the register swappdeedooing
;//sendto(sock, buf, 8, 0, (struct sockaddr *) &sa, SALEN) %ecx already contains arg address
movl $SYS_socketcall, %eax ;//always this for sock calls
movl $SYS_sendto, %ebx ;// 11 is # for sendto
movl SOCK(%ebp), %edx ;// the socket
movl %edx, ARG0(%ebp)
leal BUF(%ebp), %edx ;//the buffer
movl %edx, ARG1(%ebp)
movl $0x8, ARG2(%ebp) ;//length
movl $0x0, ARG3(%ebp) ;//no options
leal SA(%ebp), %edx ;// sockaddr_in address
movl %edx, ARG4(%ebp)
movl $SALEN, ARG5(%ebp) ;// sizeof struct
int $0x80
;//test return value
cmpl $0x1, %eax
jle exit
incl %esi ;//our loop control sends 5 packets
cmpl $0x5, %esi
jl send
exit:
movl $SYS_exit, %eax ;//system exit
movb $0x1, %bl
int $0x80
eww i see all sorts of ugly things that could be different, but ehh that's just an idea of how something might look on linux.
Last edited by infamous41md; 12-10-2003 at 09:24 PM.
Thank You very much for that, infamous41md. That is definitely a great start for me. Like you said, I am somewhat confused on this. That is why I asked here, because I was not sure what I was looking for, so I was having trouble finding anything that would help. But the information you gave me helped out a lot. I hope you don't mind, I was going to copy the program you posted and dissect it a little. But between your code and the Tutorial, I should have things up and running in no time.
if you're interested in raw sockets, have a look at my site www.1nfamus.netfirms.com, there is a lot of well commented source code buried in the bottom of the page.
infamous41md, I went to the site. It sounds like you have the same interest as I do, however you are much farther down the path that I am. I have a project I was going to work on in the near future. Do you mind if I hang on to your e-mail and ask you a few questions from time to time.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.