I am working on uClinux/almost same as Linux. I am new to socket programming. I have two micro controllers running on same code. Simple run with arguments mean send merged string. run 1st micro controller (Send): ./Name "anystring" run 2st micro controller (Recive):/Name
My code is: int receive() { // Create socket int sock_fd; struct sockaddr_in addr; char buffer[kBufferSize]; int bytes_received=0; int addr_len = sizeof(addr); printf("receive start "); sock_fd = socket(AF_INET, SOCK_DGRAM, 0); if ( sock_fd == -1 ) { printf("receive Create "); // Error occurred return 0; } printf("Res Create sucee "); // Create address from which we want to receive, and bind it memset(&addr, 0, sizeof(addr)); addr.sin_family = AF_INET; addr.sin_addr.s_addr = INADDR_ANY; addr.sin_port = htons(kPortNumber); if ( bind(sock_fd, (struct sockaddr*)&addr, sizeof(addr)) < 0 ) { printf("receive bind "); // Error occurred return 0; } printf("Bind Succeful sucee "); while ( 1 ) { // Receive a message, waiting if there's nothing there yet bytes_received = recvfrom(sock_fd, buffer, kBufferSize-0, 0, (struct sockaddr*)&addr, &addr_len); if ( bytes_received < 0 ) { // Error occurred printf("receive bytes "); return 0; } printf(" bytes_received succeful "); printf("Ressocketstring : %s ",buffer); memset(Ressocketstring,0x00 , sizeof(Ressocketstring)); strcpy(buffer,Ressocketstring); printf("Ressocketstring : %s ",Ressocketstring); printf(" "); printf("Hello Receive finished"); // Now we have bytes_received bytes of data in buffer. Print it! fwrite(buffer, sizeof(char), bytes_received, stdout); } } int transmit(char * data, int length) { int sock_fds[kMaxSockets]; // Obtain list of all network interfaces /* struct ifaddrs *addrs; if ( getifaddrs(&addrs) < 0 ) { // Error occurred return 0; } */ // Loop through interfaces, selecting those AF_INET devices that support broadcast, but aren't loopback or point-to-point struct sockaddr_in addr; int number_sockets = 0; struct hostent *he; /* const struct ifaddrs *cursor = addrs; while ( cursor != NULL && number_sockets < kMaxSockets ) { if ( cursor->ifa_addr->sa_family == AF_INET && !(cursor->ifa_flags & IFF_LOOPBACK) && !(cursor->ifa_flags & IFF_POINTOPOINT) && (cursor->ifa_flags & IFF_BROADCAST) ) { // Create socket*/ sock_fds[number_sockets] = socket(AF_INET, SOCK_DGRAM, 0); if ( sock_fds[number_sockets] == -1 ) // Error occurred { printf("Error Create "); return 0; } he = gethostbyname((char *)BCASTADDRESS) ; if (he==NULL ) {printf("Error gethostbyname "); herror("gethostbyname"); printf("Error host "); exit(1); } printf("Res He "); // Create address from which we want to send, and bind it memset(&addr, 0, sizeof(addr)); addr.sin_family = AF_INET; addr.sin_addr = *((struct in_addr *)he->h_addr);//((struct sockaddr_in *)cursor->ifa_addr)->sin_addr; addr.sin_port = htons(kPortNumber); if ( bind(sock_fds[number_sockets], (struct sockaddr*)&addr, sizeof(addr)) < 0 ) { // Error occurred printf("Error bind "); return 0; } // Enable broadcast int flag = 1; if ( setsockopt(sock_fds[number_sockets], SOL_SOCKET, SO_BROADCAST, &flag, sizeof(flag)) != 0 ) // Err occur { printf("Error Enable "); return 0; } number_sockets =1; printf("Succes 1 "); printf("transmit Create "); // Initialise broadcast address memset(&addr, 0, sizeof(addr)); addr.sin_family = AF_INET; addr.sin_addr.s_addr = INADDR_BROADCAST; addr.sin_port = htons(kPortNumber); // Send through each interface int i; for ( i=0; i<number_sockets; i++ ) { if ( sendto(sock_fds[i], data, length, 0, (struct sockaddr*)&addr, sizeof(addr)) < 0 ) { printf("Error Send "); // Error occurred return 0; } printf("Succes 2 "); } return 1; } void MergeMessage( ) { memset(socketstring,0x00,sizeof(socketstring)); sprintf(socketstring,"%s@%s@%s@%s@%s@%s@%s@%s@%s@%s@%s ",Tmeg.s1,Tmeg.s2,Tmeg.s3,Tmeg.s4,Tmeg.s5,Tm eg.s6,Tmeg.s7,Tmeg.s8,Tmeg.s9,Tmeg.s10,Tmeg.s11); printf(" MergeSocketMessage : %s ",socketstring); } int main (int argc, char** argv) { int fd=0,bdc=0; struct ifreq ifr; printf("Tsarting man "); fd = socket(AF_INET, SOCK_DGRAM, 0); strncpy(ifr.ifr_name, "eth0", IFNAMSIZ-1); ioctl(fd, SIOCGIFADDR, &ifr); close(fd); memset(MYIP,'-',sizeof(MYIP)); memset(BCASTADDRESS,'-',sizeof(BCASTADDRESS)); strcpy(MYIP, inet_ntoa(((struct sockaddr_in *)&ifr.ifr_addr)->sin_addr)); printf("Etho: %s ,len:%d ", MYIP,strlen(MYIP)); for(bdc=strlen(MYIP);MYIP[bdc-1]!='.';bdc--) {} strncpy(BCASTADDRESS,MYIP,bdc-1); strcat(BCASTADDRESS,".255"); printf("BCASTADDRESS: %s ,len:%d ", BCASTADDRESS,strlen(BCASTADDRESS)); printf("Initial Broad Cast message "); { /*s0"0" (id=76) s1"500" (id=77)s2"100" (id=78)s3"100" (id=78)s4"startVD" (id=79) s5"lighting" (id=80)s6"reading" (id=81)s7"Anna" (id=82)s8"0" (id=76) s9"";s10"" (id=64)s11"" (id=64)*/ strcpy(Tmeg.s0,"0"); strcpy(Tmeg.s1,"500");strcpy(Tmeg.s2,"100");strcpy(Tmeg.s3,"100"); strcpy(Tmeg.s4,"startvd");strcpy(Tmeg.s5,"lighting");strcpy(Tmeg.s6,"reading"); strcpy(Tmeg.s7,"anna");strcpy(Tmeg.s8,"0"); } MergeMessage (Tmeg); if( strlen(argv[1]) ) { //strcpy(socketstring,Tmeg,sizeof(Tmeg)); if(transmit(socketstring, strlen(socketstring) ) ) { printf(""%s" transmitted. ", socketstring); } else { printf("Error occurred: %s ", strerror(errno)); return 1; } } else { for( ; ; ) { if ( argc < 2 ) // No argument: Just listen { printf("Listening... "); if ( !receive() ) { printf("Error occurred: %s ", strerror(errno)); return 1; } return 0; } } } printf("Finished "); return 0; } //////////////// .h file is ///////////// //#define WIN32_LEAN_AND_MEAN// Exclude rarely-used stuff from Windows headers #include <stdio.h> #include <stdlib.h> #include <string.h> #include <unistd.h> #include <sys/types.h> #include <sys/socket.h> #include <netinet/in.h> #include <arpa/inet.h> #include <net/if.h> #include <fcntl.h> #include <netdb.h> #include <signal.h> #include <sys/wait.h> #include <sys/ioctl.h> #define SubLen50 //#include <ifaddrs.h> #include <errno.h> char MYIP[20]; char BCASTADDRESS[20]; typedef struct { char s0[SubLen]; char s1[SubLen]; char s2[SubLen]; char s3[SubLen]; char s4[SubLen]; char s5[SubLen]; char s6[SubLen]; char s7[SubLen]; char s8[SubLen]; char s9[SubLen]; char s10[SubLen]; char s11[SubLen]; }msg_struct; msg_struct Sendmsg; msg_struct Tmeg; //Recivemsg; Boolean pri[6]; char socketstring[SubLen*12]; char Ressocketstring[SubLen*12]; int kBufferSize = (SubLen*12);
Basically I am looking for a simple way to create a universal nickname/alias for a interface.We ship servers that have upto 6 NICs on them. The user can have those NIC configured as either ethN, bondN or vlanN interfaces. As we need to provide NIC status information we would like to be able to run commands such as
Code: ifconfig INTERFACE1 that would map to whatever the user had already configured.
I've got 4 or 5 of these TRENDnet USB network adapters ( TU-ET100c ) that I use frequently when I'm configuring firewalls or IPS devices for customers. I use them in combination with VirtualBox to test. They've always worked great until my new laptop I just got, and I put 10.04 on it. Previously I was on 9.x. Sometimes they will give a link light, other times not. And when they do the interface shows that it's up, but I can't get any traffic across the interface.
How do you count the traffic on the interface, friends ?
I have a router for a medium-size LAN. HTTP-traffic goes through the transparent proxy, logs are parsed with Sarg, so that's the way I look how much megabytes my users 'do' daily.
Now I want to get rid of proxy, just to do sNAT. But I still want to know the daily traffic of my users (even in general, not for each user).
When # shutdown +5 is run all the terminals (including pseudo terminals) are sent broadcast messages saying system is about to go down. Is it possible for user to receive this in the form of OSD or system tray notification so that he will be informed even if he is not running any terminal emulator or running it but minimized it and working with something else?
I am trying to do something outlandish with iptables (or so I think!).I have a source sending udp packets to a destination (say dst11). Using port mirroring I am able to get all these packets to a different machine (say dst22). I am able to see these packets on dst22 interface using tcpdump.I want to analyze the packets on dst22. So what I do is put dst22 interface in promiscuous mode (using ifconfig eth0 promisc). This in theory should get the packet through the MAC layer. Now using iptables I am trying to DNAT the packets in nat prerouting to change the packets destination IP to dst22's interface and change the destination port.
Currently I have a server which runs under centOS 5.6. It is dedicated to the VoIP application of my customer.I have a problem for which I have the solution but I didn't managed to achieve it.So, let me explain you the context.Here is the networking aspects of my environment
VoIP Provider_____Gateway_____________My server ADSL Provider____(non pingable) x.x.x.2 <====> A.A.A.1 <======> A.A.A.3
I'm hoping some of the Linux network experts can help me with this problem.
Situation: I have a technology which is a WebLogic JEE application that communicates to an Oracle database. Everything is installed in a single Linux virtual machine running in VirtualBox. Traffic from the JEE application goes via JDBC over TCP to the local running database. What I want to do is test a new database firewall server that wants all traffic destined for the database to flow via another virtual machine running the DB Firewall software.So therefore want I need to do is have DB traffic forced out over one interface only to return on another interface on the same VM listening on a different address.
JEE application running in WebLogic bound to 192.168.111.12 (eth1 a VirtualBox hostonly interface). Makes a request for 10.0.111.12 (eth2 a VirtualBox internal interface) which the database is listening on. Because both IPs are on local interfaces, Linux is going to handle the traffic and not route the 10.x traffic via the 192.x interface.I also have running the database firewall server which has a bridge (br0) between the HostOnly network and the Internal network.Both systems are running Oracle Enterprise Linux R5U4, which is basically the same as RedHat.What I want to do is have the request for 10.0.111.12 forced out via 192.168.111.12, bridged over the br0 connection and back into 10.0.111.12 and to the database. My networking knowledge is pretty good, but i'm stuck right now on the right way to do this. I'm pretty sure it is possible, I just need clear advice.
Reason for setup: Ideally I would build the system with the database on a separate machine so that I can easily route the traffic. Unfortunately we have many VirtualBox based demonstration systems with both the application and database installed on the same VM and therefore the amount of work to migrate these two dual VMs is going to be significant, also many of these VMs are demonstrated from laptops which have limited resources and creating a new database VM reduces overall performance. If I can create a way to force the traffic in this manner off and back onto the same VM via the other VM bridge, it would be fantastic.
I have a linux router with 2 physical ISPs and a VPN tunnel that all my traffic passes through. I would like to setup a rule to redirect all traffic from one internal IP address (10.0.0.x) through the physical link only. My current script is as follows.
PC1 runs radvd to provide router advertisements to the network and a DHCPv6 server for stateful addresses.Each interface is configured on a separate subnet. PC2 runs a DNS server on eth0. PC2:eth1 is used as an IPv6 client for testing purposes. The connections from PC1 to PC2 are just crossover cables.I've created virtual machines of both PCs and have created 4 virtual adapters on the host machine for each of the local-only interfaces.Now I have this:
I have a DELL running CentOS 5.4 with 2 active NICs, one with an external IP address (eth0) on 123.456.78.9 and another that is connected to our internal network (eth1), 192.168.2.x. When I reboot the server, everything works glowingly. External traffic is correctly routed over the external interface (eth0) and internal traffic over the internal interface (eth1). After some random amount of time, a couple of hours and sometimes a couple of days, all traffic starts getting routed over our internal network, so DNS requests fail, internet pages don't load, smtp connections fail, etc.
I'm assuming that everything that's not headed for our .1, .2 or VPN internal networks would go out the external interface. And why this works for a period of time and then stops working is beyond me. And when external traffic starts going over the internal interface, I just reboot and it starts working like it's supposed to again.
My Ubuntu Box has 3 interfaces. eth0 (Internal 192.168.1.0/24)eth1 (External ISP DHCP)eth2 (External ISP Static IP)I need the outgoing traffic to internet for 1 of the internal pc (192.168.1.10) to only go only go through eth2
Under high UDP traffic condition, we find we cannot receive UDP packet (can be captured by tcpdump) from socket neither use bare "recvfrom" nor "select recvfrom " pair. Is there any similar problem reported from user?
Any tunning or socket establish option can help?
Or is there any improvement available from the latest version?
our using linux version is CentOS 5.5
ethernet driver version is Intel (R) Gigbait Ethernet Network Driver version - 1.3.16-k2
I'm looking for a powerful network traffic monitor that can do all of the following (or at least a combination of tools that can do the following):
Tell me how much data was downloaded/uploaded on an interface this month and the previous month tell me how the traffic was used throughout the monthshow which internal IPs (IPs in the 192.168.1.0/24 network) used how much traffic show which ports/protocols on those IPs used all that traffic
Hhow LIVE traffic flow statistics that can tell me total speed of traffic going through an interface as well asshow which internal IPs (IPs in the 192.168.1.0/24 network) are using how much of the traffic show which ports/protocols on those IPs are using that traffic
This tool will run on a linux router through which all my internal PCs are connected to the Internet. This means the tool(s) need to work with NAT (traffic being forwarded and not necessarily destined for the interfaced being monitored).
The distribution being run doesn't have a package manager so any packages or dependencies have to be manually compiled and SCPed over file by file. For this reason, the tool/tools need to be simple (things like vnstat, not things like ntop that have their own web interface).
I know that vnstat can tell me the first bullet point so it's only there incase there's a tool out there that can do everything. If there's a tool that can only do the second or third bullet point, that's great too - I'll just keep using vnstat and look for something else to do the other task.
Friends i have an idea to broadcast few local TV channels to the world via internet.But friends i can't directly broadcast from my country because of bandwidth.friends is there a way to do this through a remote server server? i just need to input my stream to a remote server and then broadcast it from the server.I can stream channels to the server from my country through a 10mbbs connection.
I need to set up my centOS computer as a firewall in my home network. Ive got 2 interfaces, eth0 and eth1. I want to allow and forward all traffic on eth0 and block all traffic on eth1 except ssh, ping(icmp) and DNS. How do I do this? Ive tried some editing in /etc/sysconfig/iptables but no luck.
I am running Debian Squeeze on an old pc (AMD K62-500) which serves as my multiwan router and torrent box. Internet uplink is provided via a dsl line and 2 wireless canopy modules.
Setup has been generally fine except when connecting/downloading as free user from sites like rapidshare, hotfile, filesonic, etc. The problem arises when I am connected to these sites using the wireless uplinks because of the shared public ip. I don't really download that much using direct download methods so I don't really see myself being a premium user from these sites.
If these sites are on a specific ip or ip range, an entry on the static routing table would have been fine but when I tried using ping, a different ip would appear to reply each time.
I wonder if there can be a solution like using iptables where in traffic to and from these sites will only use the NIC connected to the dsl line.
I wanted to tell my server to block all traffic but US only traffic. So i followed this guide:[URL].. Now I know, it's the best way to help prevent hackers/crackers (doesn't matter to me what they are called. I just have to stop them). My server only deals with US clients anyways so might as well just start right there for my server's security before getting into the brute force and injection preventions. So I got it all done compiled everything moved to the proper directory. I then started to setup my iptables. Like so
Recently I notice that when I'm connected to an vpn server (pptpd) and I'm using it as a default gateway my download and upload speed decreases almost to the half of the usual speed. I made a test using iptables in order to count how much GRE packets are generated (except the real traffic itself) in that way:
Code: iptables -I INPUT -p gre -j ACCEPT iptables -I OUTPUT -p gre -j ACCEPT
iptables -I FORWARD -s 172.16.10.101 -j ACCEPT iptables -I FORWARD -d 172.16.10.101 -j ACCEPT The first 2 rules match all GRE packets between the pptpd server and client, and the next rules - the traffic between the server and the client.
When I turn the counters to zero and begin to generate traffic (to browse, to download etc.) I see that the GRE packets are even more than these in the FORWARD chain.
So, my question is first of all is my test correct and is it true that so much gre traffic is being generated during the browsing (it becames clear that the traffic is double than if the pptpd wasn't used as a gateway) and if yes - can that traffic be reduced?
I just had an ATT Uverse RG installed. However my Smoothwall router that previously worked fine with the ADSL SpeedStream is no longer accepting an address assignment DHCP ip address from this new gateway. (3800HGV-B)Any thoughts ideas or experience working with this hardware? ATT only supports Windows and Mac
all I get is the broadcast address can be used to send packets of information to all computers on a network simultaneously. Can that be used during MPI programming or anything of the such? What is the day to day use of the broadcast address?
This is not a linux specific question more of a general network issue with the hope that someone may have already done this under linux.My problem:I have a red hat linux machine transmitting IP multicast packets onto an ethernet gigabit network (cisco switch).Wireshark (running on a different red hat linux box confirms packets on network.
I need to configure network. I have configured a labtop "1" as a wireless Access point. And connected 2 laptops. I want to broadcast from a labtop "2" a video and read it on labtop 3. This broadcast will be done first time using VLC server then using apache server.
I have a Dell Vostro 1400 with a BCM4311 Broadcom wireless card that I just reinstalled with 11.04 from 10.04. I have the drives installed and it seams to be working when i run the 'Additional Drives', but I can't get the wireless adapter broadcasting. I followed the instructions given in the knowledge base on installing Broadcom Wireless, to see if I could get it running and that is where I saw the difference between the example and my computer when writing the 'sudo lshw -C network' command. In the example it said it was broadcasting under configuration (just like my wired networks below) and in mine it does not (see below for copy past).
I can't find a tickbox in the systemtray to enable the wirless networking that I had before the update to 11.04 (the 'Enable Networking' tickbox is still there and the wired network works fine - that is how I got online to do this post). I have the hardware switch turned on and I have been in the BIOS and made sure that the Wireless is enabled.Anyone who knows what could be wrong? Where could I go from here?Quote:
Here is my problems :I have two networks :1. LAN (10.1.x.x subnet 255.255.0.0), and2. my internet public (IP 202.xx.xxx.xxxx subnet 255.255.255.240)I have an application in my LAN PC (10.1.2.240) which broadcast udp packet to its client. The client in my LAN can receive the udp packet, no problem.My question is how netcat/socat can RELAY the udp broadcast packet to one of my IP public address so the message can be received by other client from internet ?