![]() |
| | #1 |
| Registered User Join Date: Aug 2009
Posts: 1
| Code: #include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <stdio.h>
#include <unistd.h> /* close() */
#include <string.h> /* memset() */
#define LOCAL_SERVER_PORT 100
#define MAX_MSG 500
int main(int argc, char *argv[])
{
int sd, rc, n, cliLen;
struct sockaddr_in cliAddr, servAddr;
char msg[MAX_MSG];
/* socket creation */
sd=socket(AF_INET, SOCK_DGRAM, 0);
if(sd<0) {
printf("%s: cannot open socket \n",argv[0]);
exit(1);
}
/* bind local server port */
servAddr.sin_family = AF_INET;
servAddr.sin_addr.s_addr = htonl(INADDR_ANY);
servAddr.sin_port = htons(LOCAL_SERVER_PORT);
rc = bind (sd, (struct sockaddr *) &servAddr,sizeof(servAddr));
if(rc<0) {
printf("%s: cannot bind port number %d \n",
argv[0], LOCAL_SERVER_PORT);
exit(1);
}
printf("%s: waiting for data on port UDP %u\n",
argv[0],LOCAL_SERVER_PORT);
/* server infinite loop */
while(1)
{
/* init buffer */
memset(msg,0x0,MAX_MSG);
/* receive message */
cliLen = sizeof(cliAddr);
n = recvfrom(sd, msg, MAX_MSG, 0,(struct sockaddr *) &cliAddr, &cliLen);
printf("Fail\n");
if(n<0)
{
printf("%s: cannot receive data \n",argv[0]);
continue;
}
/* print received message */
printf("%s: from %s:UDP%u : %s \n",
argv[0],inet_ntoa(cliAddr.sin_addr),
ntohs(cliAddr.sin_port),msg);
}/* end of server infinite loop */
return 0;
}
Sorry i should have added a few things, first is that this is only the a part of the program i need to write. I need to capture and condition UDP packets from some instruments that i have running. I've tryed using many different ports, i've looked up these ports in the Windows command window. After doing some research, i've found that Windows wants exclusive control over the ports it is using. I've used wireshark and i can caputure packets that way but i can't condition the data using it. I need to know/find a way to unblock these ports. Thank you! Last edited by smash_boxes; 08-07-2009 at 10:36 AM. Reason: More information to give |
| smash_boxes is offline | |
| | #2 |
| Jaxom's & Imriel's Dad Join Date: Aug 2006 Location: Alabama
Posts: 801
| The source for wireshark is out there. Same kind of deal. It may be more trouble than it is worth to hack it, though. |
| Kennedy is offline | |
| | #3 | |
| Registered User Join Date: Sep 2004 Location: California
Posts: 2,845
| Quote:
__________________ bit∙hub [bit-huhb] n. A source and destination for information. | |
| bithub is offline | |
| | #4 | |
| subminimalist Join Date: Jul 2008 Location: NYC
Posts: 3,944
| Quote:
When I googled "pcap windows", I found this: WinPcap, The Packet Capture and Network Monitoring Library for Windows Which, low and behold, "is the packet capture and filtering engine of" wireshark, among other things. *these are a riot w/ wifi
__________________ Accuracy and integrity mean nothing if you don't make it past the censors...PYTHAGORAS | |
| MK27 is offline | |
| | #5 |
| Senior software engineer Join Date: Mar 2007 Location: Portland, OR
Posts: 5,381
| An AF_INET/SOCK_DGRAM socket will not allow to to capture anything except UDP traffic. Moreover, you cannot capture packets with a destination MAC that differs from your interface MAC, unless you put the interface into promiscuous mode. Just use libpcap and be done with it.
__________________ "Congratulations on your purchase. To begin using your quantum computer, set the power switch to both off and on simultaneously." -- raftpeople@slashdot |
| brewbuck is offline | |
| | #6 |
| C++ Witch Join Date: Oct 2003 Location: Singapore
Posts: 10,352
| Moved to Networking/Device Communication forum.
__________________ C + C++ Compiler: MinGW port of GCC Build + Version Control System: SCons + Bazaar Look up a C/C++ Reference and learn How To Ask Questions The Smart Way |
| laserlight is online now | |
![]() |
| Tags |
| c programming, communication, ethernet, packets, sockets |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| segmentation fault while writing a packet to a pacp file | Neminath | C Programming | 4 | 05-05-2009 05:35 AM |
| Global Variables | Taka | C Programming | 34 | 11-02-2007 03:25 AM |
| Obtaining source & destination IP,details of ICMP Header & each of field of it ??? | cromologic | Networking/Device Communication | 1 | 04-29-2006 02:49 PM |
| Raw Packet (sorry tripple weird Post) | Coder87C | Networking/Device Communication | 6 | 03-04-2006 11:34 AM |