int ccnl_eth_sendto(int sock, unsigned char *dst, unsigned char *src, unsigned char *data, int datalen) { short type = htons(CCNL_ETH_TYPE); unsigned char buf[2000]; int hdrlen; strcpy((char*)buf, eth2ascii(dst)); DEBUGMSG(99, "ccnl_eth_sendto %d bytes (src=%s, dst=%s)\n", datalen, eth2ascii(src), buf); hdrlen = 14; if ((datalen+hdrlen) > sizeof(buf)) datalen = sizeof(buf) - hdrlen; memcpy(buf, dst, 6); memcpy(buf+6, src, 6); memcpy(buf+12, &type, sizeof(type)); memcpy(buf+hdrlen, data, datalen); return sendto(sock, buf, hdrlen + datalen, 0, 0, 0); }
void ccnl_simu_ethernet(void *dummy, void *dummy2) { if (etherqueue) { int i, qlen; struct ccnl_ethernet_s **pp, *p; // pick the last element in the queue for (qlen = 1, pp = ðerqueue; (*pp)->next; pp = &((*pp)->next)) qlen++; p = *pp; *pp = NULL; for (i = 0; i < 5; i++) { if (!memcmp(p->dst, &relays[i].ifs[0].addr.eth.sll_addr, ETH_ALEN)) { break; } } if (i < 5) { sockunion sun; sun.sa.sa_family = AF_PACKET; memcpy(sun.eth.sll_addr, p->src, ETH_ALEN); DEBUGMSG(DEBUG, "simu_ethernet: sending %d Bytes to %s, (qlen=%d)\n", p->len, eth2ascii(p->dst), qlen); ccnl_core_RX(relays + i, 0, (unsigned char*) p->data, p->len, &sun.sa, sizeof(sun.eth)); } else { DEBUGMSG(WARNING, "simu_ethernet: dest %s not found\n", eth2ascii(etherqueue->dst)); } ccnl_free(p); } ccnl_set_timer(2000, ccnl_simu_ethernet, dummy, dummy2); }
void ccnl_ll_TX(struct ccnl_relay_s *ccnl, struct ccnl_if_s *ifc, sockunion *dest, struct ccnl_buf_s *buf) { int rc; switch(dest->sa.sa_family) { #ifdef USE_IPV4 case AF_INET: rc = sendto(ifc->sock, buf->data, buf->datalen, 0, (struct sockaddr*) &dest->ip4, sizeof(struct sockaddr_in)); DEBUGMSG(DEBUG, "udp sendto %s/%d returned %d\n", inet_ntoa(dest->ip4.sin_addr), ntohs(dest->ip4.sin_port), rc); /* { int fd = open("t.bin", O_WRONLY | O_CREAT | O_TRUNC); write(fd, buf->data, buf->datalen); close(fd); } */ break; #endif #ifdef USE_ETHERNET case AF_PACKET: rc = ccnl_eth_sendto(ifc->sock, dest->eth.sll_addr, ifc->addr.eth.sll_addr, buf->data, buf->datalen); DEBUGMSG(DEBUG, "eth_sendto %s returned %d\n", eth2ascii(dest->eth.sll_addr), rc); break; #endif #ifdef USE_UNIXSOCKET case AF_UNIX: rc = sendto(ifc->sock, buf->data, buf->datalen, 0, (struct sockaddr*) &dest->ux, sizeof(struct sockaddr_un)); DEBUGMSG(DEBUG, "unix sendto %s returned %d\n", dest->ux.sun_path, rc); break; #endif default: DEBUGMSG(WARNING, "unknown transport\n"); break; } (void) rc; // just to silence a compiler warning (if USE_DEBUG is not set) }
void ccnl_ll_TX(struct ccnl_relay_s *ccnl, struct ccnl_if_s *ifc, sockunion *dest, struct ccnl_buf_s *buf) { int rc; switch(dest->sa.sa_family) { case AF_INET: rc = sendto(ifc->sock, buf->data, buf->datalen, 0, (struct sockaddr*) &dest->ip4, sizeof(struct sockaddr_in)); DEBUGMSG(99, "udp sendto %s/%d returned %d\n", inet_ntoa(dest->ip4.sin_addr), ntohs(dest->ip4.sin_port), rc); break; #ifdef USE_ETHERNET case AF_PACKET: rc = ccnl_eth_sendto(ifc->sock, dest->eth.sll_addr, ifc->addr.eth.sll_addr, buf->data, buf->datalen); DEBUGMSG(99, "eth_sendto %s returned %d\n", eth2ascii(dest->eth.sll_addr), rc); break; #endif #ifdef USE_UNIXSOCKET case AF_UNIX: rc = sendto(ifc->sock, buf->data, buf->datalen, 0, (struct sockaddr*) &dest->ux, sizeof(struct sockaddr_un)); DEBUGMSG(99, "unix sendto %s returned %d\n", dest->ux.sun_path, rc); break; #endif default: DEBUGMSG(99, "unknown transport\n"); break; } rc = 0; // just to silence a compiler warning (if USE_DEBUG is not set) }