plan9port

fork of plan9port with libvec, libstr and libsdb
Log | Files | Refs | README | LICENSE

udpread.3 (1198B)


      1 .TH UDPREAD 3
      2 .SH NAME
      3 udpread, udpwrite \- read and write UDP packets
      4 .SH SYNOPSIS
      5 .B #include <u.h>
      6 .PP
      7 .B #include <libc.h>
      8 .PP
      9 .B #include <ip.h>
     10 .PP
     11 .B 
     12 .nf
     13 .ta +4n +8n
     14 typedef struct Udphdr Udphdr;
     15 struct Udphdr
     16 {
     17 	uchar	raddr[IPaddrlen];	/* remote address and port */
     18 	uchar	laddr[IPaddrlen];	/* local address and port */
     19 	uchar	rport[2];
     20 	uchar	lport[2];
     21 };
     22 .PP
     23 .B
     24 long	udpread(int fd, Udphdr *hdr, void *data, long n)
     25 .PP
     26 .B
     27 long udpwrite(int fd, Udphdr *hdr, void *data, long n)
     28 .SH DESCRIPTION
     29 .I Udpread
     30 and
     31 .I udpwrite
     32 read and write UDP packets from the UDP network connection
     33 established on file descriptor
     34 .IR fd .
     35 .PP
     36 .I Udpread
     37 reads at most
     38 .I n
     39 bytes of packet body into
     40 .I data ,
     41 stores the header in
     42 .IR hdr ,
     43 and returns the number of bytes stored in
     44 .IR data .
     45 .PP
     46 .I Udpwrite
     47 writes the
     48 .I n
     49 bytes stored in 
     50 .I data
     51 in a UDP packet with header
     52 .IR hdr .
     53 .PP
     54 Note that the
     55 .B Udphdr
     56 frames the addresses as local and remote
     57 instead of source and destination.
     58 Thus the
     59 .I hdr
     60 filled in for a packet read by
     61 .I udpread
     62 can be used unchanged in
     63 .I udpwrite
     64 to send a response back to the sender of the original packet.
     65 .SH SOURCE
     66 .B \*9/src/lib9/udp.c
     67 .SH SEE ALSO
     68 .MR ip (3)