generic/udp_proto.c
int udp_write(int fd, char *buf, int len)
{
     register char *ptr;
     register int wlen;

     if (!is_rmt_fd_connected) return 0;

     ptr = buf - sizeof(short);

     *((unsigned short *)ptr) = htons(len); 
     len  = (len & VTUN_FSIZE_MASK) + sizeof(short);

     while( 1 ){
	if( (wlen = write(fd, ptr, len)) < 0 ){ 
	   if( errno == EAGAIN || errno == EINTR )
	      continue;
	   if( errno == ENOBUFS )
	      return 0;
	}
	/* Even if we wrote only part of the frame
         * we can't use second write since it will produce 
         * another UDP frame */  
        return wlen;
     }
}
/* Functions to read/write UDP frames. */
Functions to read/write UDP frames.
Functions to read / write UDP frames .
int udp_write(int fd, char *buf, int len)
{
     register char *ptr;
     register int wlen;
     if (!is_rmt_fd_connected) return 0;
     ptr = buf - sizeof(short);
     *((unsigned short *)ptr) = htons(len); 
     len  = (len & VTUN_FSIZE_MASK) + sizeof(short);
     while( 1 ){
	if( (wlen = write(fd, ptr, len)) < 0 ){ 
	   if( errno == EAGAIN || errno == EINTR )
	      continue;
	   if( errno == ENOBUFS )
	      return 0;
	}
        return wlen;
     }
}
int udp_write ( int fd , char * buf , int len ) { register char * ptr ; register int wlen ; if ( ! is_rmt_fd_connected ) return 0 ; ptr = buf - sizeof ( short ) ; * ( ( unsigned short * ) ptr ) = htons ( len ) ; len = ( len & VTUN_FSIZE_MASK ) + sizeof ( short ) ; while ( 1 ) { if ( ( wlen = write ( fd , ptr , len ) ) < 0 ) { if ( errno == EAGAIN || errno == EINTR ) continue ; if ( errno == ENOBUFS ) return 0 ; } return wlen ; } }
Functions to read/write UDP frames.
Functions to read / write UDP frames .
/* Even if we wrote only part of the frame
         * we can't use second write since it will produce 
         * another UDP frame */