Re: How to send udp packets over the internet.
- From: gordonb.05hb6@xxxxxxxxxxx (Gordon Burditt)
- Date: Wed, 11 Mar 2009 16:18:01 -0500
What requests do you expect to make of a web server using *UDP*?
I know of no web server that will respond to it. Web servers
generally use TCP.
Thanks for the hint.
You might open up a TCP connection to port
80 (or possibly an alternate port), and send a request like:
GET /index.php HTTP/1.1\r\nHost:www.yahoo.com\r\n\r\n
In telnet, it is very easy. Telnet does the job of creating a standard
packet with the above contents for me. I need to create the packet
myself. What'd be the structure? Is it something like this?
I'd open a socket, connect() it and write() the data something like this:
write(fd, "GET /index.php HTTP/1.1\r\nHost:www.yahoo.com\r\n\r\n", 47);
(Hope I computed the length correctly. Don't send the \0 at the end of
the string.)
I could also fdopen() the socket file descriptor, then output
the data with fprintf() or fwrite(), with fflush() to force
transmission before expecting an answer.
TCP (not telnet) does all the packet creation and I don't have to
worry about it. Incidentally, I'd likely take the same approach
with UDP if I expect to have an extended conversation (e.g. more
than one request / one response) with the same server. No headers
to mess with, just write() the data for one packet in one write()
call.
If you don't have your own TCP stack, you'll need to create one.
A single TCP packet may need to be retransmitted, and it needs to
keep the TCP sequence numbers consistent with the packets used to
set up the connection.
struct RDTHeader {
struct in_addr peer_ip;
unsigned short int peer_port;
unsigned short int seq_num;
unsigned short int length;
unsigned char flags;
unsigned char code;
SHASH hash;
unsigned char data[DFLT_SEG_SIZE +1];
};
And I shall put the contents in data?
I am just stuck at this point.
I've left out IP options and TCP options here. Header file references
are from FreeBSD, but this is probably the same for other BSD UNIX
systems.
A TCP packet *as transmitted on ethernet* consists of:
ethernet header (see <net/ethernet.h>)
IP header (see <netinet/ip.h>)
TCP header (see <netinet/tcp.h>)
data
A UDP packet *as transmitted on ethernet* consists of:
ethernet header (see <net/ethernet.h>)
IP header (see <netinet/ip.h>)
UDP header (see <netinet/udp.h>)
data
.
- References:
- How to send udp packets over the internet.
- From: Atiqur Rahman
- Re: How to send udp packets over the internet.
- From: Gordon Burditt
- Re: How to send udp packets over the internet.
- From: Atiqur Rahman
- How to send udp packets over the internet.
- Prev by Date: Re: using terminfo without a tty file descriptor (in ELinks)?
- Next by Date: Re: implement route command
- Previous by thread: Re: How to send udp packets over the internet.
- Next by thread: Re: How to send udp packets over the internet.
- Index(es):
Relevant Pages
|