/*
 * This program is GPL.
 * (C) 2003 T. Klausmann
 * compile with: gcc bind_err.c -o bind_err
 */

#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <errno.h>
#include <string.h> /* for memset */
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>

int main(void)
{
    int sockfd, sockfd2;
    struct sockaddr_in m_addr, m_addr2;
    struct in_addr ipaddr, ipaddr2;

    sockfd=socket(PF_INET, SOCK_DGRAM, 0);
    sockfd2=socket(PF_INET, SOCK_DGRAM, 0);

    memset(&m_addr, 0, sizeof(m_addr));
    memset(&m_addr2, 0, sizeof(m_addr2));

    /* Change these to an IP on your box */
    ipaddr.s_addr=inet_addr("192.168.0.1");
    ipaddr2.s_addr=inet_addr("192.168.0.1");

    m_addr.sin_port=htons(7777);
    m_addr2.sin_port=htons(7777);
    m_addr.sin_addr=ipaddr;
    m_addr2.sin_addr=ipaddr2;

    if (0 != bind(sockfd, (struct sockaddr *) &m_addr, sizeof(m_addr))) {
        perror("First bind failed");
        return(1);
    }

    printf("First bind ok\n");
    
    if (0 != bind(sockfd2, (struct sockaddr *) &m_addr2, sizeof(m_addr2))) {
        perror("Second bind failed");
        return(1);
    } 

    printf("Second bind ok\n");
    
    printf("Sleeping 120 seconds\n");
    sleep(120);

    close(sockfd);
    close(sockfd2);

    return(0);
}

