/*this function accept a socket and a pointer to a null term string
to send. the functino will make sure that all the bytes of the string are
sent. Return 1 on success and 0 on failure */
int send_string(int sockfd, unsigned char *buffer) {
int sent_bytes, bytes_to_send;
bytes_to_send = strlen(buffer);
while(bytes_to_send > 0) {
send_bytes = send(sockfd, buffer, bytes_to_send, 0);
if(sent_bytes == -1)
return 0; //error
bytes_to_send -= sent_bytes;
buffer += sent_bytes;
}
return 1;// success
}
/* this function accepts a socket a pointer to a destination
buffer. It will receive from the socket until the EOL byte
sequence is seen. the EOL bytes are read from the socket
but the destination buffer is terminationed before these bytes.
Returns the size of the read line(without EOL bytes) */
//int recv_line(
/*struct for ethernet headers */
#define ETHER_ADDR_LEN 6
#define ETHER_HDR_LEN 14
struct ether_hdr {
unsigned char ether_dest_addr[ETHER_ADDR_LEN]; //destination MAC
unsigned char ether_src_addr[ETHER_HDR_LEN]; //source mac
unsigned short ether_type; // type of ethernet packet
}
//for next week add the IP and TCP header to this file.