C/ajinject.c
/* aj_xmitframe accepts a 8-bit array of data, and a number of bytes to send
   with an open socket.  If we are blocking on the socket, just transmit the
   data and return 0 is send returns the same number of bytes sent.  If we are
   in nonblock mode, perform a select on the socket and if it is available for
   writing, send the data.  If it is not available for writing, we loop and 
   keep trying to send until select returns the socket as available.  Note that
   this behavior is different from the aj_recvframe function that will
   immediately return of select indicates that the socket is not ready to
   deliver a frame. */
aj_xmitframe accepts a 8-bit array of data, and a number of bytes to send
with an open socket.  If we are blocking on the socket, just transmit the
data and return 0 is send returns the same number of bytes sent.  If we are
in nonblock mode, perform a select on the socket and if it is available for
writing, send the data.  If it is not available for writing, we loop and
keep trying to send until select returns the socket as available.  Note that
this behavior is different from the aj_recvframe function that will
immediately return of select indicates that the socket is not ready to
deliver a frame.
aj_xmitframe accepts a 8 - bit array of data and a number of bytes to send with an open socket . If we are blocking on the socket just transmit the data and return 0 is send returns the same number of bytes sent . If we are in nonblock mode perform a select on the socket and if it is available for writing send the data . If it is not available for writing we loop and keep trying to send until select returns the socket as available . Note that this behavior is different from the aj_recvframe function that will immediately return of select indicates that the socket is not ready to deliver a frame .
int aj_xmitframe(char *ifname, u8 *xmit, int len) {
    int xmitlen = 0;
    int n = 0, sock;
    struct timeval tv;
    fd_set saved_set, wset;
    if((sock = aj_getsocket(ifname)) < 0) {
        perror("aj_getsocket");
        close(sock);
        return(-1);
    }
    if (aj_getnonblock(ifname) == 0) {
        xmitlen = write(sock, &xmit, len);
    } else {
        FD_ZERO(&saved_set);
        FD_SET(sock, &saved_set);
        tv.tv_sec = 0;
        tv.tv_usec = 250000;
        while(1) {
            wset = saved_set;
            n = select(sock+1, NULL, &wset, NULL, &tv);
            if (n < 0) {
                if (errno == EINTR || errno == EAGAIN) {
                    printf("write would block: %d.  continuing.\n", errno);
                    continue;
                } else {
                    fprintf(stderr, "select on write socket returned %d.\n", 
                        errno);
                    return(-1);
                }
            } else if (n == 0) {
                continue;
            } else {
                printf("select returned %d.\n", n);
                printf("before send errno: %d\n", errno);
                xmitlen = write(sock, &xmit, len);
                printf("after send errno: %d\n", errno);
                printf("send returned %d.\n", xmitlen);
                break;
            }
        } 
    }
    close(sock); 
    if (len == xmitlen) {
        return(0);
    } else {
        fprintf(stderr, "send returned %d, not %d bytes.\n", xmitlen, len);
        perror("write");
        return(-1);
    }
}
int aj_xmitframe ( char * ifname , u8 * xmit , int len ) { int xmitlen = 0 ; int n = 0 , sock ; struct timeval tv ; fd_set saved_set , wset ; if ( ( sock = aj_getsocket ( ifname ) ) < 0 ) { perror ( " " ) ; close ( sock ) ; return ( -1 ) ; } if ( aj_getnonblock ( ifname ) == 0 ) { xmitlen = write ( sock , & xmit , len ) ; } else { FD_ZERO ( & saved_set ) ; FD_SET ( sock , & saved_set ) ; tv . tv_sec = 0 ; tv . tv_usec = 250000 ; while ( 1 ) { wset = saved_set ; n = select ( sock + 1 , NULL , & wset , NULL , & tv ) ; if ( n < 0 ) { if ( errno == EINTR || errno == EAGAIN ) { printf ( " \n " , errno ) ; continue ; } else { fprintf ( stderr , " \n " , errno ) ; return ( -1 ) ; } } else if ( n == 0 ) { continue ; } else { printf ( " \n " , n ) ; printf ( " \n " , errno ) ; xmitlen = write ( sock , & xmit , len ) ; printf ( " \n " , errno ) ; printf ( " \n " , xmitlen ) ; break ; } } } close ( sock ) ; if ( len == xmitlen ) { return ( 0 ) ; } else { fprintf ( stderr , " \n " , xmitlen , len ) ; perror ( " " ) ; return ( -1 ) ; } }
aj_xmitframe accepts a 8-bit array of data, and a number of bytes to send
with an open socket.
aj_xmitframe accepts a 8 - bit array of data and a number of bytes to send with an open socket .
/* We are blocking, just transmit the data */ /* We are nonblock, perform a select on the socket */ /* debug */ /* timeout expired before a filehandle was populated.  
                   try again. */ /* select returned > 0, transmit the packet */ /* end while(1) */