Thread: Des. Port & Src. Port Verification Method!

  1. #1
    Registered User
    Join Date
    Jul 2004
    Posts
    14

    Des. Port & Src. Port Verification Method!

    Hi there,

    I'm trying to check on the value of two variables dst_port & src_port if any of them is 23 then service=the one who has that value.
    so,let take this example1;

    dst_port = 23;
    src_port= 2000;

    then service=dsp_port;

    other example;
    dst_port = 2000;
    src_port= 23;

    then service=src_port;

    I'm thinking of using bitwis operations, but not clear how yet.

    Any clue ??

  2. #2
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,218
    service = dst_port == 23 ? dst_port : src_port == 23 ? src_port : 0;

    Note that that only sets service to 23 or 0. You don't know which variable it got the 23 from though. You could do it like this instead though:

    int *service = dst_port == 23 ? &dst_port : src_port == 23 ? &src_port : NULL;

    Then service will be a pointer to the correct port if that's important to you. In either case, service will be 0 (or NULL if you go with the second code snippet) if neither one of them was 23.

  3. #3
    Registered User
    Join Date
    Mar 2003
    Posts
    143
    Why not
    Code:
    if ((dst_port == 23) || (src_port == 23)) {
      service = 23;
    }
    I don't think bit-wise operations are the way to go in this case
    DavT
    -----------------------------------------------

  4. #4
    Obsessed with C chrismiceli's Avatar
    Join Date
    Jan 2003
    Posts
    501
    Quote Originally Posted by DavT
    Why not
    I don't think bit-wise operations are the way to go in this case
    What bitwise operations, if you are referring to the logical or (||), you are wrong.
    Help populate a c/c++ help irc channel
    server: irc://irc.efnet.net
    channel: #c

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. FTP program
    By jakemott in forum Linux Programming
    Replies: 14
    Last Post: 10-06-2008, 01:58 PM
  2. brace-enclosed error
    By jdc18 in forum C++ Programming
    Replies: 53
    Last Post: 05-03-2007, 05:49 PM
  3. Segmentation Fault - Trying to access parallel port
    By tvsinesperanto in forum C Programming
    Replies: 3
    Last Post: 05-24-2006, 03:28 AM
  4. Basic port scanner code .. pls help ???
    By intruder in forum C Programming
    Replies: 18
    Last Post: 03-13-2003, 08:47 AM
  5. DOS, Serial, and Touch Screen
    By jon_nc17 in forum A Brief History of Cprogramming.com
    Replies: 0
    Last Post: 01-08-2003, 04:59 PM