Sponsored Content
Full Discussion: Network Code
Top Forums Programming Network Code Post 302492741 by perleo on Tuesday 1st of February 2011 10:26:34 AM
Old 02-01-2011
Network Code

Hi,

This has been bugging me all day, I'm trying to get this code to send an ipv6 destination options header to any client that connects to it. I keep getting "Error returned from sendmsg" which is my error checking on the sendmsg function but I don't know why. Any Ideas?

Code:
#include <sys/types.h>
#include <sys/socket.h>

#include <netinet/in.h>

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <netdb.h>

#include <netinet/ip6.h>

int 
main()
{
  struct sockaddr_in6 sin6, sin6_accept;
  socklen_t sin6_len;
  int s0, s;
  int on;
  char hbuf[NI_MAXHOST];
  
  //ext header
  int rv;
  struct msghdr msg;
  struct cmsghdr *cmsg;
  int cmsglen = 0;
  
  char tstmsg[13] = "Hello World";
  
  struct iovec vec;
  
  struct ip6_dest dest;
  
  memset(&sin6, 0, sizeof(sin6));
  sin6.sin6_family = AF_INET6;
  sin6.sin6_len = sizeof(sin6);
  sin6.sin6_port = htons(5001);
  
  s0 = socket(AF_INET6, SOCK_STREAM, IPPROTO_TCP);
  on = 1;
  
  //setsockopt(s0, SOL_SOCKET, SO_RESUEADDR, &on, sizeof(on));
  
  setsockopt(s0, IPPROTO_IPV6, IPV6_V6ONLY, &on, sizeof(on));
  
  bind(s0, (const struct sockaddr *)&sin6, sizeof(sin6));
  listen(s0, 1);
  while(1) {
            sin6_len = sizeof(sin6_accept);
            s = accept(s0, (struct sockaddr *)&sin6_accept, &sin6_len);
            getnameinfo((struct sockaddr *)&sin6_accept, sin6_len,
                          hbuf, sizeof(hbuf), NULL, 0, NI_NUMERICHOST);            
            printf("accept a connection from %s\n", hbuf);
            
            
            memset(&dest, 0, sizeof(dest));
            
            /* Ancilliary Data  */
            msg.msg_name = &sin6;
            msg.msg_namelen = sizeof(sin6);
            
            msg.msg_iov = &vec;
            msg.msg_iovlen = 1;
            msg.msg_iov->iov_base = tstmsg;
            msg.msg_iov->iov_len = 13;
            
            
            cmsglen = CMSG_SPACE(sizeof(dest));
            
            cmsg = malloc(cmsglen);
            
            if(cmsg == NULL) {
              puts("cmsg malloc failed");
              exit(1);
            }          
            
            msg.msg_control = cmsg;
            msg.msg_controllen = cmsglen;
            
            cmsg = CMSG_FIRSTHDR(&msg);                        
            cmsg->cmsg_level = IPPROTO_IPV6;
            cmsg->cmsg_type = IPV6_DSTOPTS;
            cmsg->cmsg_len = CMSG_LEN(sizeof(dest));
            memcpy(CMSG_DATA(cmsg), &dest, sizeof(dest));
            
            setsockopt(s0, IPPROTO_IPV6, IPV6_DSTOPTS, &on, sizeof(int)); 
            
            //send message back
            rv = sendmsg( s0 , &msg, 0);          
              if(rv == -1)
               {
                 puts("Error returned from sendmsg");
               }
           }
    exit(0);
}

 

8 More Discussions You Might Find Interesting

1. Programming

Help in developing a Network Appliation to monitor pc in a network

I am developing a Network Appliation to monitor computers in a network. Specs are App monitors the current web page viewed in each system App also can shutdown the computer in the network App can show all process run by each computer in the network I am now confused how to start my... (2 Replies)
Discussion started by: valaparambil88
2 Replies

2. IP Networking

ssh server is attachable from local network not from another network

hello i have a ubuntu ssh server that i can acess from any of my comnputers but only if they are on the same wireless network as the server. i tested trhis my tehtehring my samsung blackjack to my windows partition and installing openssh to windows it works when windows is on the wireless but no... (1 Reply)
Discussion started by: old noob
1 Replies

3. Solaris

configure zones to have different network interface and network

i need to configure a zone to use different interface (bge2) than global and have connected to completely different network switch & to use its own defaultrouter and hosts file .. is it possible ..if so ..how ? Thanks (9 Replies)
Discussion started by: skamal4u
9 Replies

4. UNIX and Linux Applications

Access to network interface (Mac-network)

Hi, I'm a italian student. For my thesis I develop a gateway with protocol 6lowpan. For that I must access to network interface to develope my personal stack based on standard 802.15.4. Can you help me? I need an explanation for that. (0 Replies)
Discussion started by: berny88
0 Replies

5. UNIX for Dummies Questions & Answers

Does SCP return an error code for network issues

Hello everyone, In a script, I am using SCP to copy huge file to another host. scp -qrp hugefile.txt /opt/perf05/tmp However, we have noticed that this file is not being copied. I am suspecting this was because we are losing connection while copying this... (1 Reply)
Discussion started by: qwarentine
1 Replies

6. Solaris

No network cable But Network interface is UP and Running

I've one Netra 240 After changing main board and system configuration card reader, Network is not accessible any more, Network interfaces are always UP and Running even when there is no cable connected to Network interfaces. I tried to restart and plumb/unplumb with no luck. ifconfig -a... (7 Replies)
Discussion started by: samer.odeh
7 Replies

7. Red Hat

Network becomes slow and return fast only after restart network

Hi, I have 2 machines in production environment: 1. redhat machine for application 2. DB machine (oracle) The application doing a lot of small read&writes from and to the DB machine. The problem is that after some few hours the network from the application to the DB becomes very slow and... (4 Replies)
Discussion started by: moshesa
4 Replies

8. IP Networking

I would like to monitor network traffic for a computer on my network

My son does homework on a school laptop. I was thinking about setting up a gateway on my home network, so that I can monitor web traffic and know if he is doing his homework without standing over his shoulder. Ideally I would like to use the Raspberry Pi Model b that I already have. However, I... (15 Replies)
Discussion started by: gandolf989
15 Replies
AnyEvent::XMPP::Error::MUC(3pm) 			User Contributed Perl Documentation			   AnyEvent::XMPP::Error::MUC(3pm)

NAME
AnyEvent::XMPP::Error::MUC - MUC error Subclass of AnyEvent::XMPP::Error METHODS type This method returns either: join_timeout If the joining of the room took too long. no_config_form If the room we requested the configuration from didn't provide a data form. subject_change_forbidden If changing the subject of a room is not allowed. message_error If this is an unidentified message error. If we got a presence error the method "presence_error" returns a AnyEvent::XMPP::Error::Presence object with further details. However, this class tries to provide a mapping for you (the developer) to ease the load of figuring out which error means what. To make identification of the errors with XEP-0045 more clear I included the error codes and condition names. Here are the more descriptive types: password_required Entering a room Inform user that a password is required. (Condition: not-authorized, Code: 401) banned Entering a room Inform user that he or she is banned from the room (Condition: forbidden, Code: 403) room_locked Entering a room Inform user that the room does not exist and someone is currently creating it. (Condition: item-not-found, Code: 404) room_not_creatable Entering a room Inform user that room creation is restricted (Condition: not-allowed, Code: 405) use_reserved_nick Entering a room Inform user that the reserved roomnick must be used (Condition: not-acceptable, Code: 406) not_on_memberlist Entering a room Inform user that he or she is not on the member list (Condition: registration-required, Code: 407) nickname_in_use Entering a room Inform user that his or her desired room nickname is in use or registered by another user (Condition: conflict, Code: 409) room_full Entering a room Inform user that the maximum number of users has been reached (Condition: service-unavailable, Code: 503) The condition and code are also available through the AnyEvent::XMPP::Error::Presence object returned by "presence_error", see below. text This method returns a human readable text if one is available. presence_error Returns a AnyEvent::XMPP::Error::Presence object if this error origins to such an error and not some internal error. message_error Returns a AnyEvent::XMPP::Error::Message object if this error origins to such an error and not some internal error. AUTHOR
Robin Redeker, "<elmex at ta-sa.org>", JID: "<elmex at jabber.org>" COPYRIGHT &; LICENSE Copyright 2007, 2008 Robin Redeker, all rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. perl v5.14.2 2012-01-23 AnyEvent::XMPP::Error::MUC(3pm)
All times are GMT -4. The time now is 06:24 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy