Sponsored Content
Top Forums Programming Simple Network Program Difficulties Post 17665 by AtleRamsli on Tuesday 19th of March 2002 05:34:51 AM
Old 03-19-2002
I wonder if you speak about two kinds of 'characters' lets say that an array contains

"ABCD" - those are four characters.
If you treat that as an integer you get the number
1145258561, or 0x44434241 - this is probaby what the original poster meant - _converted_ to characters, a number will take more space.
But any sequence of bytes can be seen as anything, char, float, char*, struct foo*,

So, when a network protocol sends 'characters'- you can make those characters mean anything you want, put two together, and you have a 16 bit short, etc.
But beware of how your machine stores integers!
The bytes above may have looked like
"BADC" on some machines to give the same number!
If I am not mistaken, I think the IBM PC is one of them ...

Look at
man htonl
man htons

Then you will understand why it just sends 'characters'- to make it an 'int'you use one of those functions, that puts the bytes in the right 'network'order, and put them back to local 'machine' order.


I often randomize characters with the % operator.

rand() % 10 gives 0-9

rand() % ('z'-'a') + 'a' is also an interesting contruct

Some fun: Remember that characters, int, floats and all that are really just bits.
If you want char is a certain range, maybe you can just chop off some bits!
0123456701234567
1001010011101011
0000111110000000 <- maybe you just want those
-----------------
0000010010000000

This would make it fast by just using one machine op,

AND byte, 000011111

Last edited by AtleRamsli; 03-19-2002 at 07:27 AM..
 

10 More Discussions You Might Find Interesting

1. Programming

QUESTION...simple program?

I am new to the unix/linux environment. AND........ I need to create a mini shell..that displays prompt (i.e., READY:$), accepts a command from std-in, and prints the command and any parameters passed to it. HELP!!!! (8 Replies)
Discussion started by: jj1814
8 Replies

2. Programming

a simple chat program

any suggestions on how i could create a simple chat program between two terminals using pipes? thanks (1 Reply)
Discussion started by: kelogs1347
1 Replies

3. Shell Programming and Scripting

Simple program but problem-pls Help

Hi All, I have problem in the following shell script (problem in 2and3 line i guess) #!/bin/sh set value1 = 90; set value2 = 70; if ; then echo "$value1 is normal" else echo "$value2 is abnormal" fi when executed output: $ value_test.sh (Enter) is abnormal Neither it's printing... (13 Replies)
Discussion started by: user__user3110
13 Replies

4. Shell Programming and Scripting

Creating simple shell program

Hi, I'm new to UNIX shell programming... can anyone help in doing the following : 1) create a text file named "Model File" having following columns : Name Number Physics Chemistry 2) prompt user to n rows enter the name, number, physics ,chemistry 3) display the entire columns and rows... (1 Reply)
Discussion started by: Mayuri P R
1 Replies

5. Programming

Xlib simple program.

I don't know if it is right to ask you this. Can someone help me write a simple Xlib program,with button on it,and all that button do is switch 2 messages. I have tried and tried,but never get past Hello World. Can someone help me please? ---------- Post updated at 10:17 PM ---------- Previous... (2 Replies)
Discussion started by: megane16v
2 Replies

6. UNIX for Dummies Questions & Answers

What's wrong with this simple program in APUE?

I start wetting my toes in Linux programming. I tried the first program myls.c in Advanced Programming in the Unix Environment. #include <sys/types.h> #include <dirent.h> #include "apue.h" int main(int argc, char *argv) { DIR *dp; struct... (1 Reply)
Discussion started by: cqlouis
1 Replies

7. Shell Programming and Scripting

simple program help required

The circumfrence of a circle is #!/usr/bin/perl print 2 * 3.141592654 * 12.50 \n"; # pi= 3.141592654 # r= 12.50 I need a simple program showing me all the steps..to modify the above to prompt for and accept a radius from the person running the... (3 Replies)
Discussion started by: Q2wert
3 Replies

8. Shell Programming and Scripting

Help with simple program. (beginner)

Hey all, Writing a program that searches for a username and if they are online creates a 'beep' and sends the username and date to a log file. the error i am getting is: paul.obrien16@aisling:~/os$ bash checklogin : command not found Enter username paul.obrien16 ': not a valid... (2 Replies)
Discussion started by: sexyladywall
2 Replies

9. UNIX for Dummies Questions & Answers

Help with creating a simple program!!

i am new to shell scripting!! i am making this program in bourne shell, that asks the user to input "Hello (their name)" or "question (their name)", any other input, "ERROR" will be outputted. if they input "Hello (name)", i want to out saying Hello (name) but if they input "question (name)", i... (4 Replies)
Discussion started by: bshell_1214
4 Replies

10. Programming

A simple C program query ...

Given the following code inside the function ext3_write_super(): (It's there in Linux kernel 2.6.27.59) static void ext3_write_super (struct super_block * sb) { if (mutex_trylock(&sb->s_lock) != 0) BUG(); sb->s_dirt = 0; } The conditional test at if... (2 Replies)
Discussion started by: Praveen_218
2 Replies
sasl_server_start(3SASL)		      Simple Authentication Security Layer Library Functions			  sasl_server_start(3SASL)

NAME
sasl_server_start - create a new server authentication object SYNOPSIS
cc [ flag ... ] file ... -lsasl [ library ... ] #include <sasl/sasl.h> int sasl_server_start(sasl_conn_t *conn, const char *mech, const char *clientin, unsigned *clientinlen, const char **serverout, unsigned *serveroutlen); DESCRIPTION
The sasl_server_start() interface begins the authentication with the mechanism specified by the mech parameter. sasl_server_start() fails if the mechanism is not supported. PARAMETERS
conn The SASL context for this connection. mech The mechanism name that the client requested. clientin The initial response from the client. The value of clientin is NULL if the protocol lacks support for the client-send-first or if the other end did not have an initial send. No initial client send is distinct from an initial send of a null string. The protocol must account for this difference. clientinlen The length of the initial response. serverout Created by the plugin library. The value of serverout is the initial server response to send to the client. serverout is allocated or freed by the library. It is the job of the client to send it over the network to the server. Protocol specific encoding, for example base64 encoding, must be done by the server. serveroutlen The length of the initial server challenge. RETURN VALUES
sasl_server_start() returns an integer that corresponds to a SASL error code. ERRORS
SASL_OK Authentication completed successfully. SASL_CONTINUE The call to sasl_server_start() was successful, and more steps are needed in the authentication. All other error codes indicate an error situation that must be handled, or the authentication session should be quit. See sasl_errors(3SASL) for information on SASL error codes. ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Availability |SUNWlibsasl | +-----------------------------+-----------------------------+ |Interface Stability |Evolving | +-----------------------------+-----------------------------+ |MT-Level |MT-Safe | +-----------------------------+-----------------------------+ SEE ALSO
gethostname(3C), sasl_errors(3SASL), attributes(5) SunOS 5.10 1 Oct 2003 sasl_server_start(3SASL)
All times are GMT -4. The time now is 08:47 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy