reSIProcate/stack  9694
testSource.cxx
Go to the documentation of this file.
00001 #if defined(HAVE_CONFIG_H)
00002 #include "config.h"
00003 #endif
00004 #include <sys/types.h>
00005 #include <sys/socket.h>
00006 #include <netinet/in.h>
00007 #include <stdlib.h>
00008 #include <string.h>
00009 #include <netinet/in.h>
00010 #include <arpa/inet.h>
00011 #include <iostream>
00012 #include "rutil/Data.hxx"
00013 #include "rutil/DnsUtil.hxx"
00014 #include "rutil/Tuple.hxx"
00015 
00016 int
00017 main(int argc, char *argv[])
00018 {
00019 
00020    int sockfd;
00021    char buffer[1024];
00022 
00023    socklen_t len;
00024    struct sockaddr_in cliaddr, servaddr;
00025 
00026    if (argc != 2)
00027    {
00028       exit(0);
00029    }
00030    using namespace resip;
00031 
00032    sockfd = socket(AF_INET, SOCK_DGRAM, 0);
00033 
00034    memset(&servaddr, 0, sizeof(servaddr));
00035    servaddr.sin_family = AF_INET;
00036    const int serv_port = 9999;
00037    servaddr.sin_port = htons(9999);
00038 
00039    inet_pton(AF_INET, argv[1], &servaddr.sin_addr);
00040    inet_ntop(AF_INET, &servaddr.sin_addr, buffer,1024);
00041    
00042    std::cout << "Sending to : " << buffer << std::endl;
00043    
00044    connect(sockfd, (const sockaddr*)&servaddr, sizeof(servaddr));
00045 
00046    len = sizeof(cliaddr);
00047    getsockname(sockfd, (sockaddr*)&cliaddr, &len);
00048    inet_ntop(AF_INET, &cliaddr.sin_addr, buffer, 1024);
00049    std::cout << "new local source is: " << buffer << std::endl;
00050    std::cout << "DnsUtil::inet_ntop = " 
00051              << DnsUtil::inet_ntop(cliaddr.sin_addr)
00052              << std::endl;
00053 
00054 
00055    return 0;
00056 }
00057 /* ====================================================================
00058  * The Vovida Software License, Version 1.0 
00059  * 
00060  * Copyright (c) 2000 Vovida Networks, Inc.  All rights reserved.
00061  * 
00062  * Redistribution and use in source and binary forms, with or without
00063  * modification, are permitted provided that the following conditions
00064  * are met:
00065  * 
00066  * 1. Redistributions of source code must retain the above copyright
00067  *    notice, this list of conditions and the following disclaimer.
00068  * 
00069  * 2. Redistributions in binary form must reproduce the above copyright
00070  *    notice, this list of conditions and the following disclaimer in
00071  *    the documentation and/or other materials provided with the
00072  *    distribution.
00073  * 
00074  * 3. The names "VOCAL", "Vovida Open Communication Application Library",
00075  *    and "Vovida Open Communication Application Library (VOCAL)" must
00076  *    not be used to endorse or promote products derived from this
00077  *    software without prior written permission. For written
00078  *    permission, please contact vocal@vovida.org.
00079  *
00080  * 4. Products derived from this software may not be called "VOCAL", nor
00081  *    may "VOCAL" appear in their name, without prior written
00082  *    permission of Vovida Networks, Inc.
00083  * 
00084  * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
00085  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
00086  * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
00087  * NON-INFRINGEMENT ARE DISCLAIMED.  IN NO EVENT SHALL VOVIDA
00088  * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES
00089  * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL,
00090  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00091  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00092  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
00093  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00094  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
00095  * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
00096  * DAMAGE.
00097  * 
00098  * ====================================================================
00099  * 
00100  * This software consists of voluntary contributions made by Vovida
00101  * Networks, Inc. and many individuals on behalf of Vovida Networks,
00102  * Inc.  For more information on Vovida Networks, Inc., please see
00103  * <http://www.vovida.org/>.
00104  *
00105  */