Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7856403
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T20:41:52+00:00 2026-06-02T20:41:52+00:00

Im currently working with socket programming, but i am having problems connecting to my

  • 0

Im currently working with socket programming, but i am having problems connecting to my device when testing code on a computer with multiple ethernet devices.

How can i define which ethernet device it should be using (Mac OS X)?

Source:

int sock, bytes_recieved;  
char send_data[1024],recv_data[1024];
struct hostent *host;
struct sockaddr_in server_addr;  

host = gethostbyname("192.168.100.4");

cout << "Start" << endl;

if ((sock = socket(AF_INET, SOCK_STREAM, 0)) == -1) {
    // perror("Socket");
    cout << "Socket error" << endl;
    exit(1);
}

server_addr.sin_family = AF_INET;     
server_addr.sin_port = htons(30002);   
server_addr.sin_addr = *((struct in_addr *)host->h_addr);
bzero(&(server_addr.sin_zero),8); 

if (connect(sock, (struct sockaddr *)&server_addr,
            sizeof(struct sockaddr)) == -1) 
{
    //  perror("Connect");
    cout << "Connect error" << endl;
    exit(1);
}

Thanks in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T20:41:54+00:00Added an answer on June 2, 2026 at 8:41 pm

    You can specify the listening address with the bind function.

    An address of 0.0.0.0 is used to listen on all interfaces and IP addresses belonging to the computer, alternatively you can specify a specific IP address to listen on, which will select only the interface that address belongs to

    EDIT: The MSDN example at the bottom of the page is easier to follow

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Currently I have the following code, working with Node.js, socket.io and Redis: var io
I've been working with socket programming lately; and I'm currently making a server that
Currently, I'm trying to get the lib working in my project, but with no
I'm currently working on a UDP socket application and I need to build in
I am currently working on a programming assignment. The assignment is to implement a
I am currently working on code that serializes in one app (C++) and needs
I'm currently working on a TCP socket server in C++; and I'm trying to
I am currently working on a Flash socket client for a pre-existing service/standard. The
I am currently working on a project that creates a TCP socket and listens
Currently working in the deployment of an OFBiz based ERP, we've come to the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.