c
23 TopicsHands-on C: argc and argv from main() function explained
Quick Intro Learning C is is a good way to take our understanding of Operating Systems (OS) to the next level as it touches low-level structures that other languages such as Python often abstract. I'm covering C here not only because BIG-IP runs on top of Linux but also because understanding how the OS works can help us troubleshoot more complex issues. Linux has been gaining popularity and DevOps movement certainly gave it a boost as most DevOps tools run natively on Linux. As C is the nuts and bolts of Linux 'engine', it is also no surprise that we see more Platform (DevOps) Engineers interested in learning C to extend their reach when it comes to diagnosing problems and to have a more in-depth understanding of Linux. In this article, I'm going to use a simple Hello World in C but those who already had exposure to C will also benefit from understanding more thoroughly the default arguments (argc and argv) in main() function by running the code themselves. If you already know something about C, you can skip to last section and test the code yourself. Hello World This is a hello world in Python: This is a typical hello world in C: The main() function is the way we tell C where the execution of our code should start. It is the way C language signals processor where it should look for the main piece of code to run once our program is loaded in memory. The printf() function formats and print string characters to standard output. C doesn't have an interpreter like Python as it's a compiled language. Because of this, in order to execute above code we need to compile it first, i.e. create the executable file that has the binary code ready to run. How to Compile our Hello World We usegcccommand with-oparameter pointing to the name of the executable file name. Thegcccommand compiles our code and create the executablehelloworld. It's a binary file ready to be executed. If we need to change our code, we need to re-compile our code and create another executable file. Understanding #include <library_name> Adding libraries in C is similar to other programming languages. Libraries add capabilities to your code where you can find ready-to-use functions that do something that you might need to use. C libraries end in*.h(shortfor header) and compiler searches for them in/usr/includepath by default on Linux. In this particular case here, we only added thestdio.hlibrary which is the standard C I/O library with file reading/writing/streaming handling capabilities. There are also others we might occasionally bump into in most programs: unistd.h : The Unix standard library. It has utilities for interacting with the kernel such as system calls. stdlib.h : The C standard library with many useful utilities for general data type conversion, memory allocation, etc. ctype.h : Character library with for char conversion sys/types.h : System types library which contains the most definitions for base types and structures of Linux systems. string.h : String library for C string manipulation. Why does main function have argc and argv? argc= number of arguments passed when we execute program (integer) argv= list of arguments we passed when we executed program (array) Simple answer is that this is useful stuff to have natively. It's extensively used in command line tools, for example. Let's say we're creating a command line tool and we need to retrieve the 2nd argument passed to our program. You can just retrieve it directly from main() function by callingargv[2]. No need to create an extra function for that. Let's use this simple program as an example: It should print whatever arguments I pass to it: Notice that by default, the first argument is always the program's name. Even if I don't pass any arguments that's still the case: We can conclude that every program will have at least one argument which is the name of the program itself.1.4KViews1like2CommentsGet all certificates and their virtual servers and SSL profiles via API calls
Problem this snippet solves: Summary F5 will give you a decent report of all your certificates and their expiration dates. However I have not found a way to pull what Virtual Server or SSL Profile the certificates are applied to (or if they are used at all). What this code does is grabs all the virtual servers, all SSL profiles, and all certificates. Then it loops through them to find where a certificate is applied. Then it returns the certificate and virtual server info. I wrote this in C# but the logic can be used anywhere as the API calls are independent of language. How to use this snippet: You will need some way to compile C#. Easiest way is to use Visual Studio. Simply add your API credentials and IP addresses and run the code through a C# compiler. Code : https://github.com/matthewwedlow/F5_Scripts/blob/master/GetCerts.cs2.3KViews1like3Comments